Advertisement
Kulas_Code20

Quiz

May 17th, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5.  
  6. void display(int corrects){
  7.     cout<<"_______________________"<<endl;
  8.     cout <<"#Correct Answer:" <<corrects <<endl;
  9.     int accuracy = (corrects/10)*100;
  10.     cout <<"Percentage of Accuracy:" <<accuracy<<"%" <<endl;
  11.  
  12.     if(accuracy==100){
  13.         cout <<"Perfect!" <<endl;
  14.     }
  15.     else if(accuracy>70 && accuracy <100){
  16.         cout <<"Excellent Work!" <<endl;
  17.     }
  18.     else{
  19.         cout <<"Please review more and try again." <<endl;
  20.  
  21.     }
  22. }
  23.  
  24. //Main Function
  25. int main(){
  26.     //Declare Variable
  27.     int rnum1, rnum2, add;
  28.     int answer, wrong; //Corrects is for calling in display function
  29.     int i, a, b, corrects=0, score = 0;;
  30.     char input;
  31.     srand((unsigned)time(0));
  32.     //For loop
  33.     for(i=0; i<10; i++){
  34.         rnum1=(rand()%10)+1;
  35.         rnum2=(rand()%10)+1;
  36.         //this if for the value the will add in the wrong choice.
  37.         add = (rand()%5)+1;
  38.         answer = rnum1*rnum2;
  39.         wrong = (rnum1*rnum2)+add;
  40.         //to shuffle the choices
  41.         if(rnum1>rnum2){
  42.           a = answer;
  43.           b = wrong;
  44.         } else{
  45.           b = answer;
  46.           a = wrong;
  47.         }
  48.         cout<<"_______________________"<<endl;
  49.         cout<<"How much is" <<rnum1 <<" x " <<rnum2 <<": ?"<<endl;
  50.         cout<<"A. "<<a<<endl;
  51.         cout<<"B. "<<b<<endl;
  52.         cout<<"Enter you answer: ";
  53.         cin>>input;
  54.         input = tolower(input);
  55.        
  56.         if (input == 'a'){
  57.             if(a<b){
  58.                 cout<<"Correct!" <<endl;
  59.                 score+=2;
  60.                 corrects+=1;
  61.             }else{
  62.                 cout <<"Sorry, Incorrect Answer" <<endl;
  63.             }
  64.         }
  65.         if (input == 'b'){
  66.             if(b<a){
  67.                 cout<<"Correct!" <<endl;
  68.                 score+=2;
  69.                 corrects+=1;
  70.             }else{
  71.                 cout <<"Sorry, Incorrect Answer" <<endl;
  72.             }
  73.         }
  74.        
  75.     }
  76.     cout<<"Your Score is: "<<score<<endl;
  77.     //Call Display
  78.     display(corrects);
  79.  
  80.     return 0;
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement