首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

一个小程序运行时有个警告,求解~解决思路

2013-08-23 
一个小程序运行时有个警告,求解~~用*输出cos(x)函数在0~360度区间的图像#includestdio.h#includemath.h

一个小程序运行时有个警告,求解~~
用*输出cos(x)函数在0~360度区间的图像
#include<stdio.h>
#include<math.h>
#include<iostream>
void main()
{
double y;int x,m;
for (y=1;y>=-1;y-=0.1)
{
m=acos(y)*10;
for (x=1;x<m;x++) printf(" ");
printf("*");
for(;x<62-m;x++) printf(" ");
printf("*\n");
}
system("Pause");
}

警告1warning C4244: “=”: 从“double”转换到“int”,可能丢失数据
[解决办法]
问题出在这行
m=acos(y)*10;
m是int型,acos()返回double型,因此有警告:从“double”转换到“int”,可能丢失数据

你可以使用强制类型转换,使编译器不警告
m=(int)(acos(y)*10.0);

热点排行