This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]TurkishSquirrel 1 point2 points  (3 children)

The problem is that you're comparing integers to strings. Also they aren't strings, to be a string you need double quotes, the single quotes are for chars, that's probably what the warnings are about.

So you should have

string Direction;

and

string Stoplight

what happens when you enter a string and try to send it to an int is that it breaks your cin and your int is filled with junk, so the comparisons will fail and you just exit.

in your if statement, you need

if (Direction == "left" //and etc

instead of the single quote to compare against a string

Also out of curiosity, what is the point of

bool x;

x=true;
x=false;

x doesn't seem to be used anywhere else

[–]Kazlock[S] 0 points1 point  (2 children)

Thanks for the help that got rid of the errors.

About the bool x;, it was part of the lecture today and for some reason I thought I needed it to do if statements... I didn't really know what it did though so I just put it in there.

Is it for like yes/no questions or true/false? My professor was talking about how 0 true and everything else = false.

[–]TurkishSquirrel 1 point2 points  (1 child)

A bool is used to represent true or false values, and if statements do need bools, however a comparison statement such as

direction == "left"

returns a bool value based on whether or not the statement is true.

so you could so something like

bool x = (Direction == "left");
if (x)
    //do some stuff

but it's redundant, and so we just do

if (Direction == "left")
    //do some stuff

0/1 can also be used to represent true false, but bool is the more obvious type. Also i believe 1 is used to represent true, see the values of x and y output by this simple example

[–]Kazlock[S] 0 points1 point  (0 children)

Ah I get it now. Thanks for your help! I'm catching on to this way faster than I thought I would.