我是编程新手(我正在学习C ++)。有人可以告诉我为什么在尝试运行这段代码时会收到此错误消息。
int main()
{
auto days=0, hours_worked=0;
cin >> "days"; // This is where I get the error message.
cout << "Days worked per week";
cin >> "hours_worked"; // This is where I get the error message.
cout << "Hours worked per day";
cout << "This week Paul worked: "
<<"6*9"<< endl;
return 0;
}
答案 0 :(得分:1)
#include <iostream>
using namespace std; //we are going to use std::cin, std::cout, std::endl from the header file <iostream>
int main()
{
int days=0, hours_worked=0; //why not just declare it as integer?
cin >> days; //you need to write it without "" otherwise its treated as a string and not a variable
cout << "Days worked per week" << days; //no. of days the person worked
cin >> hours_worked; // same here
cout << "Hours worked per day" << hours_worked;
cout << "This week Paul worked: "
<< (days*hours_worked) << " hours" << endl; //paul worked (days*hours_worked) hours
return 0;
}
是更正后的代码。希望你能理解这些更正。