+ 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.

27th Feb 2018, 2:59 AM
Faza
Faza - avatar
4 odpowiedzi
+ 5
if(type == "f" || type == "F"), this should work. if(condition1 OR condition2), in your case condition2 is just "F"
27th Feb 2018, 3:03 AM
teKno23
teKno23 - avatar
+ 4
if(type == "c" || type == "C")
27th Feb 2018, 3:01 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
THANKS SO MUCH!! been struggling with this for 5 dayss
27th Feb 2018, 3:04 AM
Faza
Faza - avatar
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.
27th Feb 2018, 6:16 AM
D B
D B - avatar