Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- void display(int corrects){
- cout<<"_______________________"<<endl;
- cout <<"#Correct Answer:" <<corrects <<endl;
- int accuracy = (corrects/10)*100;
- cout <<"Percentage of Accuracy:" <<accuracy<<"%" <<endl;
- if(accuracy==100){
- cout <<"Perfect!" <<endl;
- }
- else if(accuracy>70 && accuracy <100){
- cout <<"Excellent Work!" <<endl;
- }
- else{
- cout <<"Please review more and try again." <<endl;
- }
- }
- //Main Function
- int main(){
- //Declare Variable
- int rnum1, rnum2, add;
- int answer, wrong; //Corrects is for calling in display function
- int i, a, b, corrects=0, score = 0;;
- char input;
- srand((unsigned)time(0));
- //For loop
- for(i=0; i<10; i++){
- rnum1=(rand()%10)+1;
- rnum2=(rand()%10)+1;
- //this if for the value the will add in the wrong choice.
- add = (rand()%5)+1;
- answer = rnum1*rnum2;
- wrong = (rnum1*rnum2)+add;
- //to shuffle the choices
- if(rnum1>rnum2){
- a = answer;
- b = wrong;
- } else{
- b = answer;
- a = wrong;
- }
- cout<<"_______________________"<<endl;
- cout<<"How much is" <<rnum1 <<" x " <<rnum2 <<": ?"<<endl;
- cout<<"A. "<<a<<endl;
- cout<<"B. "<<b<<endl;
- cout<<"Enter you answer: ";
- cin>>input;
- input = tolower(input);
- if (input == 'a'){
- if(a<b){
- cout<<"Correct!" <<endl;
- score+=2;
- corrects+=1;
- }else{
- cout <<"Sorry, Incorrect Answer" <<endl;
- }
- }
- if (input == 'b'){
- if(b<a){
- cout<<"Correct!" <<endl;
- score+=2;
- corrects+=1;
- }else{
- cout <<"Sorry, Incorrect Answer" <<endl;
- }
- }
- }
- cout<<"Your Score is: "<<score<<endl;
- //Call Display
- display(corrects);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement