注册 登录
编程论坛 C++ Builder

求助一道编程,是税收的。

大风2387 发布于 2006-08-15 15:45, 1613 次点击

题目是。税收的计算方法是。5000元以下不收税,5001-15000收10%,15001-35000收15%,35000以上收20%。
有人收入38000那么所得税是5000*0。00+10000*0。10+20000*0。15+3000*0。20。我的程序如下,但怎么运行不起来啊,错在哪?
#include<iostream.h>
#include<conio.h>
const double lev1=5000;
const double lev2=15000;
const double lev3=35000;
const double rat1=0.1;
const double rat2=0.15;
const double rat3=0.2;
void main()

{double income;
double tax;
cout<<"Enter your income:"<<endl;
double income;
double tax;
cin>>income;
if{income<=lev1;
tax=0;}
esle if{income<=lev2;
cout<<tax=(income-lev1)*rat1<<endl;}
else if{income<=Lev3;
tax=rat1*(lev2 -lev1)+rat2*(income -lev2); }
else
{tax=rat1*(lev2 -lev1)+rat2*(lev3 -lev2)
+rat3*(income -lev3);}
}
cout<<"You owe Neutronia"<<tax<<"tvarpsintaxes."
_getch();
}

7 回复
#2
大风23872006-08-15 15:48

#include<iostream.h>
#include<conio.h>
const double lev1=5000;
const double lev2=15000;
const double lev3=35000;
const double rat1=0.1;
const double rat2=0.15;
const double rat3=0.2;
void main()

{double income;
double tax;
cout<<"Enter your income:"<<endl;
cin>>income;
if{income<=lev1;
tax=0;}
esle if{income<=lev2;
tax=(income-lev1)*rat1;}
else if{income<=Lev3;
tax=rat1*(lev2 -lev1)+rat2*(income -lev2); }
else
{tax=rat1*(lev2 -lev1)+rat2*(lev3 -lev2)
+rat3*(income -lev3);}
}
cout<<"You owe Neutronia"<<tax<<"tvarpsintaxes."
_getch();
}

#3
zzydeai2006-11-27 17:13

顶楼上

#4
爱上夜2006-12-16 15:29

我不知道现在回答晚吗 不过你的程序太多不该有的错误了
我改后的
#include<iostream.h>
#include<conio.h>
const double lev1=5000;
const double lev2=15000;
const double lev3=35000;
const double rat1=0.1;
const double rat2=0.15;
const double rat3=0.2;
void main()

{double income;
double tax;
cout<<"Enter your income:"<<endl;
cin>>income;
if(income<=lev1)
tax=0;
else if(income<=lev2)
tax=(income-lev1)*rat1;
else if(income<=lev3)
tax=rat1*(lev2 -lev1)+rat2*(income -lev2);
else
{tax=rat1*(lev2 -lev1)+rat2*(lev3 -lev2)
+rat3*(income -lev3);}
cout<<"You owe Neutronia"<<tax<<"tvarpsintaxes.";
}

#5
爱上夜2006-12-16 15:32
getch();这个在C里用 在C++不用的VC++功能远比TABC功能强大
还有if语句后要有条件表达式
#6
hiwoody2007-02-24 10:01
以下是引用大风2387在2006-8-15 15:45:43的发言:

题目是。税收的计算方法是。5000元以下不收税,5001-15000收10%,15001-35000收15%,35000以上收20%。
有人收入38000那么所得税是5000*0。00+10000*0。10+20000*0。15+3000*0。20。我的程序如下,但怎么运行不起来啊,错在哪?
#include<iostream.h>
#include<conio.h>
const double lev1=5000;
const double lev2=15000;
const double lev3=35000;
const double rat1=0.1;
const double rat2=0.15;
const double rat3=0.2;
void main()

{double income;
double tax;
cout<<"Enter your income:"<<endl;
double income;
double tax;
cin>>income;
if{income<=lev1;
tax=0;}
esle if{income<=lev2;
cout<<tax=(income-lev1)*rat1<<endl;}
else if{income<=Lev3;
tax=rat1*(lev2 -lev1)+rat2*(income -lev2); }
else
{tax=rat1*(lev2 -lev1)+rat2*(lev3 -lev2)
+rat3*(income -lev3);}
}
cout<<"You owe Neutronia"<<tax<<"tvarpsintaxes."
_getch();
}

蓝色为一个错误 红色为另一个错误 感觉你的代码好乱

代码的规范也是很重要的

这样的代码应该更清晰一点了

#include<iostream.h>

#include<conio.h>
const double lev1=5000;
const double lev2=15000;
const double lev3=35000;
const double rat1=0.1;
const double rat2=0.15;
const double rat3=0.2;
void main()
{
double income;
double tax;
cout<<"Enter your income:"<<endl;
double income;
double tax;
cin>>income;
if(income<=lev1)
tax=0;
esle if(income<=lev2)
tax=(income-lev1)*rat1;
else if(income<=Lev3)
tax=rat1*(lev2 -lev1)+rat2*(income -lev2);
else
tax=rat1*(lev2 -lev1)+rat2*(lev3 -lev2)+rat3*(income -lev3);
cout<<"You owe Neutronia"<<tax<<"tvarpsintaxes."
_getch();
}


[此贴子已经被作者于2007-2-24 10:02:16编辑过]

#7
hufen2007-03-26 17:56
爱上夜的程序好简洁啊,佩服
#8
masefee5192007-04-03 19:46
1