Hello,
I am writing a C++ program that displays a multiple choice question, and then asks the user for the answer. I am posting this because I have a couple questions regarding errors I receive. Below is the code.
- I will use a "do-while" loop, to keep the program running until the user gets the answer correct
- I will use "if" statements to give user clues when they get the answer wrong.
- I use an "if" statement when the user types in an answer not on the list of answers for the question, to let them know that they did not enter a valid answer.
Here is the Code:
Code:
// name: quiz.cpp
// author: Kautz
// date: November 9, 2008
// description: Multiple Choice Question
#include <iostream>
int main()
{
char Color;
do
{
cout << "What Color is the Sky?" << endl;
cout << "A. Blue" << endl;
cout << "B. Green" << endl;
cout << "C. Red" << endl;
cout << "A, B, or C?" << endl;
cin >> Color;
}
while (Color == B );
while (Color == C );
if (Color == B )
{cout << "Hint: Starts with the letter B" << endl;}
if (Color == C )
{cout << "Hint: Starts with the letter B" << endl;}
if (Color != A , B, C )
{cout << "You must enter either A, B, or C" << endl;}
if (Color == A )
{cout << "Correct!" << endl;}
return 0;
}
Here is a list of errors that appear:
Code:
quiz.cpp: In function `int main()':
quiz.cpp:21: `B' undeclared (first use this function)
quiz.cpp:21: (Each undeclared identifier is reported only once
quiz.cpp:21: for each function it appears in.)
quiz.cpp:22: `C' undeclared (first use this function)
quiz.cpp:28: `A' undeclared (first use this function)
I hope that someone can help me out with why there are errors and what I can do to fix them.
It would be greatly appreciated!
Thank you!