error: no match for 'operator>>' (operand types are 'std::basic_istream<char>::__istream_type {aka std::basic_istream<char>}'

*EDIT*
I'm having issues with this coding, for instance line 30 says 'error: invalid operands of types 'float' and 'int' to binary 'operator^'. Im trying to multiply two variables together while squaring one and then dividing the equation by 2.

I'm using code::blocks 16.01
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
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
    float mass;
    float height;
    int velocity;
    char option;
    bool loopback;
    float kinetic;
    float potential;

    do
    {
        cout <<" "<<endl;
        cout << "Insert the mass of the body in kg:";
        cin >> mass;
        cout << "[K]inetic    [P]otential    [E]xit" << endl;
        cout << endl;
        cout << "Select an option:";
        cin >> option;
        switch(option)
        {
            case 'K':
            case 'k':
                    kinetic = mass*velocity^2/2;
                    cout << "Please insert the velocity of the body in m/s:";
                    cin >> velocity;
                    cout << setiosflags (ios::fixed) << setprecision (2);
                    cout << "The kinetic energy of the body is " << kinetic << "Joules" << endl;
                    loopback = true;
            case 'P':
            case 'p':
                    potential = mass*9.81*height;
                    cout << "Please insert the height of the body in meters:";
                    cin >> height;
                    cout << setiosflags (ios::fixed) << setprecision (2);
                    cout << "The potential energy of the body is " << potential << "Joules" << endl;
                    loopback = true;
            case 'E':
            case 'e':
                    goto return 0;
                    loopback = false;
                    break;
            default:
                goto do;
        }
    }
    while (loopback);
    return 0;
}
Last edited on
1.
cin >> mass >> endl;

Should be :
cin >> mass; cout << endl;

2.
cin >> option >> endl;

Should be :
cin >> option; cout << endl;

Fix these problems first. Of course your code does not compile.
remove the endl from cin should look like:

cin >> mass;

You need to do this for all cin statements.
Ok, I changed the ^2 to multiply the velocity by the velocity again. so its:

kinetic = mass*velocity*velocity/2;

Now I've got this error: " expected identifier before 'do' ". Any suggestions to fix this issue? I'm not familiar with goto. But I need this switch to loop back to the initial choice selection.
Don't use goto. If the program needs to run again have loopback set to true, if it needs to exit have it set the false so it'll drop out of the loop.

Suggestion instead of haveing two cases like
1
2
 case 'E':
 case 'e':


use toupper on option
switch(toupper(option))

then just use the upper case versions like case 'E':
You will have to use #include <cctype>

Don't forget also single entry single exit, so only have 1 return statement. If you need to exit the program exit the loop.
Last edited on
Topic archived. No new replies allowed.