2014-12-24 1 views
0

저는 프로그래밍 할 때 정말 새롭습니다 (저는 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; 
} 
+5

변수 이름 주위의 따옴표를 제거하십시오. –

답변

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; 
} 

는 수정 된 코드입니다. 당신이 그 시정을 이해하기를 바랍니다.

관련 문제