薪资计算器程序

时间:2012-09-28 03:07:27

标签: c++ visual-studio-2010 visual-c++-2010

#include <iostream>
Using namespace std;

int main ();
{ 
cout << "What is the mean amount you work/week?" << endl;

if (input <= 40)
cout << "Your salary is $8.00/hour";
cin >> a1;
if (a1 <= 0)
cout << "";
cin >> a2;
if (a2 >= 40)
cout << a3
cin >> a3;

cout << "" << endl;
else
cout << " Better luck next time.- the correct answer is " << add << endl;

return 0;

我正在尝试编写一个C++程序来计算并显示由以下表达式确定的人员工资:

如果工作时间为<= 40,则此人会收到$8/hour,否则, 人员以40hrs @ $8/hr基本费率收到剩余的1.5x小时。{ 计划应该要求: 1)工作小时数(输入) 2)显示赚取的工资(输出) 使用常数变量表示基本费率,以便在每小时费率变化时轻松更新程序 给予适当的输入/输出。 测试程序多个x,其中小时,=以及40以上。

任何方向都将非常感谢!

1 个答案:

答案 0 :(得分:1)

获取一些关于C ++的好书,查看The Definitive C++ Book Guide and List

根据您的代码。这应该是

#include <iostream>

int main () {
    int hours = 0;
    int rate = 8;

    std::cout << "Enter number of working hours?";
    std::cin >> hours;

    int pay = hours * rate;

    if (40 < hours) {
        pay += (hours - 40) * (rate / 2);
    }

    std::cout << "Total Pay" << pay << std::endl;
    return 0;
}