I'm doing a quiz program in C++ programming language. I have used a for loop to go through each switch case but when I run the program, it's just keep looping the case 0 and can't stop the loop after I answering my quiz. How should I solve it ?
#include <iostream>
#include <string>
using namespace std ;
void quiz_count () ;
void display_question () ;
void question (string question , string a , string b , string c , string d , char correct_answer) ;
void result () ;
int question_num = 0 ;
int correct = 0 ;
int wrong = 0 ;
int main ()
{
display_question() ;
return 0 ;
}
void quiz_count ()
{
system("cls") ;
cout << "Question Number: " << question_num << "\t\t Correct Answer:" << correct << "\t\t Wrong Answer:" << wrong << endl << endl ;
display_question () ;
}
void display_question()
{
for (int i=0; i<10 ; i++)
{
switch (i)
{
case 0 :
question ( "1) What is recycling?" , "Buying new clothes" , "Collecting and using materials to make something new" , "Throwing things in garbage can" , "Selling items" , 'b' ) ;
break ;
case 1 :
question ( "2) What are the 3R's of the recycling?" , "Redirect, Rude, Round" , "Respectful, Responsible, Right" , "Reduce, Reuse, Recycle" , "Rewrite, Rewind, Respond" , 'c') ;
break ;
case 2 :
question ( "3) What goes into the green bin?" , "plastic" , "glass" , "cans" , "paper" , 'b' ) ;
break ;
}
}
result () ;
}
void result ()
{
system("cls") ;
cout << "The total of question is :" << question_num << endl ;
cout << "The correct answer from you is :" << correct << endl ;
cout << "The wrong answer from you is :" << wrong << endl ;
}
void question (string question , string a , string b , string c , string d , char correct_answer)
{
cout << question << endl ;
cout << "A. \t" << a << endl ;
cout << "B. \t" << b << endl ;
cout << "C. \t" << c << endl ;
cout << "D. \t" << d << endl ;
char answer ;
cout << "Please enter your answer here :" ;
cin>>answer ;
if (answer == correct_answer)
{
correct ++;
}
else
wrong ++ ;
question_num ++ ;
quiz_count() ;
}