c语言简单的程序,那错了,怎样通过下面的错误解释改正?

来源:百度知道 编辑:UC知道 时间:2024/06/08 05:40:40
#include <stdio.h>
void main()
{long i;
double b1,b2,b4,b6,b10;
int branch;

b1=100000*0.1;
b2=b1+100000*0.075;
b4=b2+200000*0.05;
b6=b4+200000*0.03;
b10=b6+400000*0.015;
printf("请输入利润:");
scanf("%ld",&i);
branch=i/100000;
if(branch>10)
branch=10;

switch(branch)
{case 0:bonus=i*0.1;break;
case 1:bonus=b1+(i-100000)*0.075;break;
case 2:
case 3:bonus=b2+(i-200000)*0.05;break;
case 4:
case 5:bonus=b4+(i-400000)*0.03;break;
case 6:
case 7:
case 8:
case 9:bonus=b6+(i-600000)*0.015;break;
case 10:bonus=b10+(i-1000000)*0.01;
}
printf("奖金是%10.2f",bonus);
}

错误解释
--------------------Configuration: 472 - Win32 Debug--------------------
Compiling...
472.cpp
E:\ccc\472.cpp(19) : error C2065: 'bonus' : undeclared identifier
E:\ccc\472.cpp

错误:bonus没有定义(就是第一个ERROR)
警告(这个无所谓):warning 是强制类型转换,出现了数据丢失,这个到无所谓。

我把bonus定义为double型的程序就运行起来了

#include <stdio.h>
void main()
{long i;
double b1,b2,b4,b6,b10,bonus;
int branch;

b1=100000*0.1;
b2=b1+100000*0.075;
b4=b2+200000*0.05;
b6=b4+200000*0.03;
b10=b6+400000*0.015;
printf("请输入利润:");
scanf("%ld",&i);
branch=i/100000;
if(branch>10)
branch=10;

switch(branch)
{case 0:bonus=i*0.1;break;
case 1:bonus=b1+(i-100000)*0.075;break;
case 2:
case 3:bonus=b2+(i-200000)*0.05;break;
case 4:
case 5:bonus=b4+(i-400000)*0.03;break;
case 6:
case 7:
case 8:
case 9:bonus=b6+(i-600000)*0.015;break;
case 10:bonus=b10+(i-1000000)*0.01;
}
printf("奖金是%10.2f",bonus);
}