Question about cin operator?? {Beginner}

Much appreciated to anyone to lend me a clue. I've been at this exercise for a few hours and cannot figure out why it will not compile. I've specified the problem the compiler says is the problem below. The problem is next to //HERE. The compiler "(codeblocks)" says "no match for 'operator>>' ". Can someone please show me what is wrong. Thanks.

This exercise is from a c++ programming book "From program analysis to program design"....The exercise says to write a program that mimics a calculator ,only (+, -, / ,*). I just wanted to go a little farther and include the modulus sign and that is where the problem comes in.


#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
double num1, num2, sum, difference, product, quotient;
int remainder, modulus1, modulus2;
char instrument, main;

cout << "C or c for regular calculator. M or m for modulus calculator.";
cin >> main;




if (main == 'C' || main == 'c')
{{
cout << fixed << showpoint << setprecision(2);
cout << "Calculate two numbers: ";
cin >> num1 >> instrument >> num2;
cout << endl << endl;

sum = num1 + num2;
difference = num1 - num2;
product = num1 * num2;
quotient = num1 / num2;

if (instrument == '+')
cout << "Sum: " << sum << endl;

else if (instrument == '-')
cout << "Difference: " << difference << endl;

else if (instrument == '*')
cout << "Product: " << product << endl;

else if (instrument == '/')
cout << "Quotient: " << quotient << endl;

if (instrument == '/' && num2 == 0)
cout << "Cannot divide by 0\n";
}}



else if (main == 'M' || main == 'm')
{{
cout << "Calculate two numbers: ";
cin >> modulus1 >> instrument >> modulus2 >> endl; //HERE
cout << endl << endl;

remainder = modulus1 % modulus2;

if (instrument == '%')
cout << "Modulus: " << remainder << endl;
}}
return 0;
}
You have an endl at the end. endl is only for cout, not cin.
As volatile said, cin does not have an endl; this is something only cout has. cin looks for input and automatically creates a new line once entered.
Wow! Much thanks!
I don't think cin automatically adds a new line. I believe it just happens to be a side effect of pressing the Enter key after your input. I might be wrong with that since I don't know the actual workings of cin, but I believe that new line character can end up getting stored into the buffer stream if you're not careful. That's what makes me believe that cin doesn't typically just add a new line.
Topic archived. No new replies allowed.