Jen
Jen

Reputation: 1

C ++ cout and cin exercice Error: main.cpp: In function ‘int main()’

I am a complete beginner and I have been looking at this code for two days and I just cant figure out what I did that keeps creating this error message:

main.cpp: In function ‘int main()’:
main.cpp:19:43: error: no match for ‘operator>>’ (operand types are ‘std::basic_ostream<char>’ and ‘const char [25]’)
  value of num1 =" << num1 >> "  and the value of num2 " << num2 >> ".";
  ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/string:53:0,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/ostream:38,
                 from /usr/include/c++/7/iostream:39,
                 from main.cpp:1:
/usr/include/c++/7/bits/basic_string.tcc:1465:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
     operator>>(basic_istream<_CharT, _Traits>& __in,
     ^~~~~~~~
/usr/include/c++/7/bits/basic_string.tcc:1465:5: note:   template argument deduction/substitution failed:
main.cpp:19:46: note:   ‘std::basic_ostream<char>’ is not derived from ‘std::basic_istream<_CharT, _Traits>’
 lue of num1 =" << num1 >> "  and the value of num2 " << num2 >> ".";
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~

#include <iostream>
#include <string>

using namespace std;

int main()
{

    //variable declaration
    int num1, num2, newNum, SECRET;
    SECRET = 11;
    double RATE = 12.50;
    string name;
    double hoursWorked, wages;

    //executable statements
    cout << "Give me two integers"; 
    cin >> num1 >> num2;
    cout << "The value of num1 =" << num1 >> "  and the value of num2 " << num2 >> ".";
    newNum = (num1*2)+num2;
    cout<< "The new value of newNum =" << newNum;
    newNum = newNum+ SECRET;
    cout<< "The new value of newNum =" << newNum;
    cout << "What's your last name?";
    cin >> name;
    cout << "Enter a decimal number between 0 and 70";
    cin >> hoursWorked;
    wages = RATE*hoursWorked;
    cout << "Name: " << name << "\n" << "Pay Rate: $" << RATE << "\n" << "Hours Worked: "<<hoursWorked << "\n" << "Salary: $  " << wages;
    return 0;
} 

Upvotes: 0

Views: 8128

Answers (2)

Kritik Sharma
Kritik Sharma

Reputation: 11

#include <iostream>
#include <string>

using namespace std;

int main()
{

//variable declaration
int num1, num2, newNum, SECRET;
SECRET = 11;
double RATE = 12.50;
string name;
double hoursWorked, wages;

//executable statements
cout << "Give me two integers"; 
cin >> num1 >> num2;
cout << "The value of num1 =" << num1 << "  and the value of num2 " << num2 << ".";
newNum = (num1*2)+num2;
cout<< "The new value of newNum =" << newNum;
newNum = newNum+ SECRET;
cout<< "The new value of newNum =" << newNum;
cout << "What's your last name?";
cin >> name;
cout << "Enter a decimal number between 0 and 70";
cin >> hoursWorked;
wages = RATE*hoursWorked;
cout << "Name: " << name << "\n" << "Pay Rate: $" << RATE << "\n" << "Hours Worked: "<<hoursWorked << "\n" << "Salary: $  " << wages;
return 0;
} 

Don't use ">>" in cout even if you are printing variable. That was a simple syntax error.

Upvotes: 0

Martin Morterol
Martin Morterol

Reputation: 2900

You used the wrong operator :

// cout << "The value of num1 =" << num1 >> "  and the value of num2 " << num2 >> ".";  
//                                  here ^               and              here ^         

You should have used :

cout << "The value of num1 =" << num1 << "  and the value of num2 " << num2 << ".";

Upvotes: 4

Related Questions