My program won't run :( NOOB question

Why wont this code run, i checked everything over many times:

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
#include <iostream.h>
#include <string>
#include <math.h>

using namespace std;

int main()
{
    char cselect, sselect;

    cout << "Hello, and welcome to Saad's Geometry Homework Helper APLHA 1.0" << endl;
    cout << "To calculate SA and V of spheres enter <s>, to minimize SA press <a>, to maximize volume press <v>" << endl;
    cin >> cselect;
    if (cselect = "s"){
        cout << "You have selected SA and V of spheres calculator. If you would like to calculate the SA, press <s>, otherwise <v> for volume" << endl;
        cin << sselect;
    }
    else if (cselect = "a"){
        cout << "You have selected minimizing surface area. For cylinders press <c>, otherwise <p> for prisms." << endl;
    }
    else if (cselect = "v"){
        cout << "You have selected maximizing volume. For cylinders press <c>, otherwise <p> for prisms." << endl;
    }
    return 0;
}
(cselect = "s")

Let's break this down.

It says:

(set the value of cselect to "s")

Did you mean (cselect == "s")?
Check again, you have a very basic, and very common beginners mistake in there.

HINT: = != ==
HINT 2: http://www.cplusplus.com/doc/tutorial/operators/
Yeah did. Its very easy to fix...

if (cselect = "s") that would set your cselect variable to s.

use "==" to check for the value "s" ... If you receive the value "s" then your code will return true and it will run the code in the if() block
So I tried what you guys said, which was changing (cselect = "s") to (cselect == "s"), but it still doesn't work. For that same line (line 14) it says:

"ISO C++ forbids comparison between pointer and integer"
Use single quotes:

(cselect == 's')

char is a single character.
Last edited on
thanks Lynx876, that seemed to solve those errors! just one last error it shows for line 16:


" error: no match for 'operator<<' in 'std::cin << sselect' "
Turn your operator the other way around!

cout <<
cin >>
wooooow, i don't know how I did not notice that LOL. thanks sooo much Lynx876 for solving my problem! thanks!
ahaha, no problem!
Topic archived. No new replies allowed.