[英]Invalid operands to binary expression error message
我真的是編程新手(正在學習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;
}
#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;
}
是正確的代碼。 希望您了解更正。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.