It has been years since I took C++ in college, so when my manager asked me to work on a project in C++ I decided I needed a refresher course. I found one online and got stuck on a simple calculator program. I believe I entered the code exactly as in the example, but receive the following error:
error: no match for 'operator>>' (operand types are 'std::basic_ostream<char>::__ostream_type {aka std::basic_ostream<char>}' and 'double')|
This is happening on the line of code that says "cin >>number_1;"
I have reviewed the forum and searched online for a solution. Most of the online resources I found imply this error means number_1 has not been properly declared, but I did declare it at the beginning of the code as "double number_1;"
I am sure I have made a simple mistake, but can't seem to figure this one out. Here is the relevant section of the code. Thank you in advance for any help.
#include <iostream>
usingnamespace std;
int main()
{
int choice;
double number_1;
double number_2;
cout<<"1.) Addition"<<endl;
cout<<"2.) Subtraction"<<endl;
cout<<"3.) Multiplication"<<endl;
cout<<"4.) Division"<<endl;
cout<<endl<<endl<<"Enter a choice: ";
cin>>choice;
switch(choice)
{
case 1:
{
cout<<"Enter first number:"; // << <--
cin >> number_1;
cout<<endl<<endl<<"Enter second number:"; // <<
cin>>number_2;
cout<<endl<<endl<<endl;
cout<<"The sum is "<<number_1+number_2;
break;
}
}
return 0;
}
1.) Addition
2.) Subtraction
3.) Multiplication
4.) Division
Enter a choice: 1
Enter first number:22
Enter second number:22
The sum is 44Program ended with exit code: 0