Uploaded by john paul pellogo

C++ multiplication machine

advertisement
#include <cmath>
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include<iostream>
using namespace std;
int main ()
{
char again;
int a, b, answer, guess; //Random numbers, answer, and user guess
int Score;
int lives = 3;
int attemp = 3;
cout << "Welcome to the Multiplication Machine.\n" << endl;
again='c';
while ((again=='c') || (again=='C'))
{ attemp++;
srand ( time(NULL) );
a = rand() % 10;
b = rand() % 10;
cout <<a << " x " << b << " = ";
cin >> guess;
answer = a * b ;
if(answer == guess){
Score++;
cout<<"score: "<<Score<<endl;
cout<<"Lives: "<<lives<<endl;
if(Score <= 4){
cout<<endl;
cout << "Correct!!!\n" << "Enter C to continue : ";
cin >> again;
cout<<endl;
}else{
int score = Score - 3 + lives;
cout<<"Googjob!!!"<<endl;
cout<<"Your Score is "<<score<<endl;
if(score == 5){
cout<<"Perfect Score You Are great!!!"<<endl;}
else if( score >= 3){
cout<<"Very good!!! you passed."<<endl;}
else{
cout<<"Oh No!!! try Again to learn"<<endl;}
break;
}
}
else{
cout<<"Score: "<<Score<<endl;
lives--;
cout<<"Lives: "<<lives<<" / 3"<<endl;
cout<<"Wrong answer!"<<endl;
cout <<"The Correct answer is "<< answer <<endl;
cout<<endl;
if(lives != 0){
cout << "Enter C to continue : ";
cin >> again;
cout<<endl;
}else{
cout<<"\nyour Score is " << Score<<endl;
if(Score == 5){ cout<<"Perfect Score You Are great!!!"<<endl;}
else if( Score >= 3){cout<<"Very good!!! you passed."<<endl;}
else{cout<<"Oh No!!! try Again to learn"<<endl;}
break;
}
}
}
return 0;
}
Download