You are viewing our Forum Archives. To view or take place in current topics click here.
Just Started, need help on if statement
Posted:

Just Started, need help on if statementPosted:

BONDGUY8514697
  • Ladder Climber
Status: Offline
Joined: Jul 29, 201212Year Member
Posts: 348
Reputation Power: 8
Status: Offline
Joined: Jul 29, 201212Year Member
Posts: 348
Reputation Power: 8
I'm trying to make a quiz, and I'm unsure as to how I should go about it. I've run into this problem.

cout << "1. What team did Jack Morris not play for? \n" << endl ;

cout << "A. Toronto Blue Jays \nB. Atlanta Braves \nC. Detroit Lions \nD. Minnesota Twins" << endl ;
cin >> one ;

if (one == "B" )
cout << " Correct " << endl ;

Would I need to create a separate variable for each answer? Whats the easiest way to do that for large amounts of questions?

Thanks.
#2. Posted:
154
  • Blind Luck
Status: Offline
Joined: May 04, 201410Year Member
Posts: 2,747
Reputation Power: 4457
Status: Offline
Joined: May 04, 201410Year Member
Posts: 2,747
Reputation Power: 4457
Get a image from the script, it's harder to pick out from just the text you've listed..?

If you can
#3. Posted:
BONDGUY8514697
  • Christmas!
Status: Offline
Joined: Jul 29, 201212Year Member
Posts: 348
Reputation Power: 8
Status: Offline
Joined: Jul 29, 201212Year Member
Posts: 348
Reputation Power: 8
Vexaah wrote Get a image from the script, it's harder to pick out from just the text you've listed..?

If you can



Gotcha.


text texttexttexttres
#4. Posted:
ip
  • Fairy Master
Status: Offline
Joined: Dec 30, 201211Year Member
Posts: 3,778
Reputation Power: 3016
Status: Offline
Joined: Dec 30, 201211Year Member
Posts: 3,778
Reputation Power: 3016
We generally use switch statements when it comes to a selection of choices like what you are describing. I'll post some code below as a starter.

string input;
cout << "What is your favorite color?" << endl;
cin >> input; // Takes the input string and sets it as the varialbe input

switch (input) // Checks to see if input = certain value
{
   case "blue": // input = blue
      cout << "That is my favorite color too!" << endl;
      break;
   case "yellow": // input = yellow
      cout << "That's a nice color!" << endl;
      break;
   case "orange": // input = orange
      cout << "That's a very bright color!" << endl;
      break;
   default: // user didn't input a color you put in the statement
      cout << "That's a nice color!" << endl;
      break;
}
If you want to ask more questions or just need a bit of help feel free to pm me.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.