I have a program with a string variable that equals whatever the user puts in. I am trying to use a switch statement to display a certain message based on the letter the user typed, but don't know how to show the switch program it is an input. I am grateful for any help, part of the code is below.
cin >> ans1;
switch(ans1 == "") {
{case "A" : cout << ": Sorry, the right answer was C.";
break;}
{case "B" : cout << ": Sorry, the right answer was C.";
break;}
{case "C" : cout << ": Correct! Wow, your pretty smart!";
break;}
{case "D" : cout << ": Sorry, the correct answer was C.";
break;}
Instead of using a
switch statement
with a variable that equals user input, you could use anif/else statement
(i.e. ans1 == 'C').Thank you
JohnnyMopp5
.