|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
#define sum 100000
int main()
{
float amount,aver,toal;
int i;
for(i = 1,total = 0;i<=1000;i++)
{
printf("please enter amount: ");
scanf("%f",&amount);
total = total +amount;
if(total>=sum) break;
}
aver = total/i;
printf("number = %d\naver = %d10.2f\n",i,aver);
return 0;
}
例题 照着书上打的,编译后出现问题。
--------------------Configuration: 061 - Win32 Debug--------------------
Compiling...
061.c
E:\c++\Microsoft Visual Studio\MyProjects\061\061.c(8) : error C2065: 'total' : undeclared identifier
E:\c++\Microsoft Visual Studio\MyProjects\061\061.c(12) : warning C4244: '=' : conversion from 'float ' to 'int ', possible loss of data
E:\c++\Microsoft Visual Studio\MyProjects\061\061.c(15) : warning C4244: '=' : conversion from 'int ' to 'float ', possible loss of data
执行 cl.exe 时出错.
061.obj - 1 error(s), 0 warning(s)
怎么解决
本帖最后由 baige 于 2020-8-25 23:35 编辑
- #include <stdio.h>
- #define sum 100000
- int main()
- {
- float amount,aver,total;// total写错了
- int i;
- for(i = 1,total = 0;i<=1000;i++)
- {
- printf("please enter amount: ");
- scanf("%f",&amount);
- total = total +amount;
- if(total>=sum) break;
- }
- aver = total/i;
- printf("number = %d\naver = %10.2f\n",i,aver);// d去掉
- return 0;
- }
复制代码
|
|