+ 2
Some how the "or" ( || ) did not work, or I just misunderstood it?? C++
temp: if (type == "f" || "F"){ conv = (temp - 32) * 5/9; cout << temp << " degree fahrenheit is " << conv << " degree celsius" << endl; getch(); system("CLS"); goto mainmenu; } if (type == "c" || "C"){ conv = (temp * 9/5) + 32; cout << temp << " degree celsius is " << conv << " degree fahrenheit" << endl; getch(); system("CLS"); goto mainmenu; } else{ cout << "Wrong input."; getch(); system("CLS"); goto temp; } goto temp; When I gave the "type" input as c or C, it somehow keep going with the first if. This only happens when I put the "||" symbol.
4 Answers
+ 5
if(type == "f" || type == "F"), this should work.
if(condition1 OR condition2), in your case condition2 is just "F"
+ 4
if(type == "c" || type == "C")
+ 2
THANKS SO MUCH!! been struggling with this for 5 dayss
0
As above: It compares two boolean values.
It's not like in speech (It's F or f)
In programming, it's like: Is it F? Yes/No? And is it f?
And then it will give you yes or no.