Syntax Error?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
        char a, s, m, d;                //variables for add, subtract, multiply, and divide;
        int first;
        int second;
        char c;
        int answer = 0;

        cout << "SIMPLE CALCULATOR" << endl;    //Title "**SIMPLE CALCULATOR**"

        cout << "Enter first number: ";         //Ask user for first number input
        cin >> first >> endl;                   //Allow user input for first number

        cout << "Enter second number: ";        //Ask user for second number
        cin >> second >> endl;                          //Allow user input for second number

        cout << "Add [1], subtract [2], multiply [3], or divide [4]?: ";        //Ask user for operator to be used
        cin >> c >> endl;

        if( c == 'a' )
        {
                answer = first+second;
        }

        if( c == 's' )
        {
                answer = first-second;
        }

        if( c == 'm' )
        {
                answer = first*second;
        }

        if( c == 'd' )
        {
                answer = first/second;
        }

        cout << "Your answer is: " << answer << endl;
        return 0;
}





Trying to make a simple calculator but my code won't compile. Get this error message followed by a long string of text:

SimpleCalculator.cpp: In function ‘int main()’:
SimpleCalculator.cpp:16: error: no match for ‘operator>>’ in ‘std::cin.std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((int&)(& first))) >> std::endl’
Last edited on
Please edit your post and make sure that your code is [code]between code tags[/code] so that it has line numbers and syntax highlighting.

Also, please copy and paste the exact first error message you are getting and indicate which line it is on.

At a quick glance, you are trying to input into endl, which doesn't make any sense.
Thanks, can't believe I didn't realize that. Works fine now and I edited line 21 to make sense with the characters declared at the beginning.
Last edited on
Topic archived. No new replies allowed.