Bold As Love
Bold As Love

Reputation: 13

Invalid operands to binary expression error message

I am really new at programming(I'm learning C++). Could somebody tell me why I get this error message when trying to run this piece of code.

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

Upvotes: 0

Views: 961

Answers (1)

technusm1
technusm1

Reputation: 533

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

is the corrected code. hope you understand the corrections.

Upvotes: 1

Related Questions