我刚开始用C ++,使用xcode。我尝试写一个简单的,如果用户工作x金额用户获得支付y金额,程序。我不确定我的内容是否正确,但我无法对其进行测试,因为我收到错误"预期的不合格内容"与第一个{。这是列出的唯一错误,我无法弄清楚如何解决它。
#include <iostream>
using namespace std;
int main ()
int user;
int salary1 = user * 12;
int salary2 = (user * 18) + 480;
{ // this is the line I'm receiving error.
cout << "Enter the number of hours you worked this week";
cin >> user;
if (user <= 40)
{
cout << "You made" << salary1 << "this week!"
}
else (user > 40)
{
cout << "You made" << salary2 << "this week!!!"
}
return 0;
}
答案 0 :(得分:1)
括号围绕整个函数体:
int main()
{ // <--- function body starts here
int user;
// rest of function body
} // <--- function body ends here
您还需要在读取salary1
的值后计算salary2
和user
的值。
答案 1 :(得分:1)
声明int主块内的变量,并在收到用户输入后计算工资。
#include <iostream>
using namespace std;
int main ()
{
int user;
cout << "Enter the number of hours you worked this week";
cin >> user;
int salary1 = user * 12;
int salary2 = (user * 18) + 480;
if (user <= 40)
{
cout << "You made" << salary1 << "this week!"
}
else (user > 40)
{
cout << "You made" << salary2 << "this week!!!"
}
return 0;
}