如何更改此代码? [英] How do I change this code ?
本文介绍了如何更改此代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是C ++编程的新学生。
这是我的练习代码。
但我在粗体文本(REGULAR_PAY)上有错误。
有什么问题!?我想知道......
#include < iostream >
使用 命名空间标准;
#define REGULAR_HOUR 125;
#define REGULAR_PAY 5580;
#define OVER_PAY 6500;
int main()
{
int 小时;
int grossPay;
int taxRate;
cout<< 输入本月的工作时间:;
cin>>小时;
if (小时< = 125 ){
grossPay =小时* REGULAR_PAY;
}
其他
grossPay = REGULAR_HOUR * REGULAR_PAY +(小时 - 125 跨度>)* OVER_PAY;
if (grossPay< 900000)
taxRate = 1 ;
else if (grossPay< = 1500000 )
taxRate = 2 ;
else if (grossPay< = 2000000 )
taxRate = 8 ;
else if (grossPay> 2000000)
taxRate = 10 跨度>;
cout<< 总薪酬= KRW<< grossPay<< endl
<< ; 所得税率=<< taxRate<< %<< endl;
}
解决方案
引用:#define REGULAR_HOUR 125 ;
#define REGULAR_PAY 5580 ;
#定义OVER_PAY 6500 ;您应该删除预处理器定义中的尾随分号。
更好,你应该摆脱预处理器定义并使用enum
代替,例如
枚举
{
REGULAR_HOUR = 125 ,
REGULAR_PAY = 5580 ,
OVER_PAY = 6500
};
I'm a new pupil of C++ programming.
This is my practice code.
But I have a error on bold text(REGULAR_PAY).
What problem is on that!? I wonder...
#include <iostream>
using namespace std;
#define REGULAR_HOUR 125;
#define REGULAR_PAY 5580;
#define OVER_PAY 6500;
int main()
{
int hour;
int grossPay;
int taxRate;
cout << "Input the worked hour of this month: ";
cin >> hour;
if (hour<=125) {
grossPay = hour*REGULAR_PAY;
}
else
grossPay = REGULAR_HOUR*REGULAR_PAY + (hour-125)*OVER_PAY;
if (grossPay<900000)
taxRate=1;
else if (grossPay<=1500000)
taxRate=2;
else if (grossPay<=2000000)
taxRate=8;
else if (grossPay>2000000)
taxRate=10;
cout << "Gross Pay = KRW "<<grossPay<<endl
<< "Income Tax Rate = "<<taxRate<<"%"<<endl;
}
解决方案
Quote:#define REGULAR_HOUR 125;
#define REGULAR_PAY 5580;
#define OVER_PAY 6500;You should remove the trailing semicolons in preprocessor defines.
Better, you should get rid of preprocessor defines and useenum
instead, e.g.
enum { REGULAR_HOUR = 125, REGULAR_PAY = 5580, OVER_PAY =6500 };
If you have a modern compiler you may also have a look at scoped enumerations[^].
这篇关于如何更改此代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文