im writing a quiz program. if the user is wrong the 1st time, he can choose to get a 2nd try, which i must display by blanking out his original choice, so instead of ABCD he only sees AB D or something. If you got an idea or can post a link id appreciate it . ive marked the problem area with // below.
int player_try (string questions[][5], char answers[] )
{
char user_guess;
int m = 0;
srand(time(NULL));
int x;
int choice;
int total = 1;
int score = 0;
for (m=0; m<6; m++)
{
x = (rand() % 7);
cout << user_name << ": Here is question number " << m+1 << endl;
cout << m+1 << ". " << questions[x][0]<< endl;
cout << "A. " << questions[x][1]<< endl;
cout << "B. " << questions[x][2]<< endl;
cout << "C. " << questions[x][3]<< endl;
cout << "D. " << questions[x][4]<< endl;
cin >> user_guess;
user_guess = toupper(user_guess);
while (!(user_guess >= 'A' && user_guess <= 'D'))
{
cout << "Please choose a valid answer.";
cin>> user_guess;
user_guess = toupper(user_guess);
}
if (user_guess != answers[x])
{
cout <<"Wrong!" <<endl;
cout << "Skip this question or try again?" << endl;
cout << "If you are wrong again... game OVER! No points!" << endl;
cout << "Press 1 to skip, press 2 to take a chance at greatness." << endl;
cin >> choice;
if (choice == '1')
{
cout << "we shall skip this question." << endl;
break;
}
else
{
cout << "I applaud your bravery." << endl;
cout << user_name << ": Here is question number " << m+1 << endl;
cout << m+1 << ". " << questions[x][0]<< endl;
cout << "A. " << questions[x][1]<< endl; // here is where im stuck
cout << "B. " << questions[x][2]<< endl; // how do i blank out an incorrect choice?
cout << "C. " << questions[x][3]<< endl; //thanks
cout << "D. " << questions[x][4]<< endl;
cin >> user_guess;
user_guess = toupper(user_guess);
I agree with Chad.
If you want a simple way to handle it, store the answer given in a variable, then add some checks to see if this answer you are writing is the same as already answered, and skip it if they are the same.