Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
resit-group-project-sem-2/main.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
160 lines (141 sloc)
4.08 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
#include <string> | |
#include <random> | |
#include <ctime> | |
#include <cstdlib> | |
int g; | |
int main() | |
{ | |
label1: | |
cout<< "welcome to the game of maths you will be asked a series of questions and try to get as far as you can.\n you have three lives\n What is your name"<<endl; | |
string playername; | |
cin>> playername; | |
int health = 3; | |
while(health > 0) | |
{ | |
srand(time(0)); // Initialize random number generator. | |
for(int i=0;i<1;i++) // number can be changed depending on how many questions | |
{ | |
g =(rand() % 5) + 1; | |
string answer; | |
if(g == 1) | |
{ | |
cout<<"what is 5 x 5"<<endl; | |
cin>> answer; | |
if(answer == "25") | |
{ | |
//SetConsoleTextAttribute(hConsole,2) | |
cout<<"Correct"<<endl; | |
//SetConsoleTextAttribute(hConsole,7) | |
} | |
else | |
{ | |
//set console attribute(hConsole,4) | |
cout<<"Incorrect"<<endl; | |
//SetConsoleTextAttribute(hConsole,7) | |
health = health-1; | |
cout<<"you have "<< | |
health<< | |
" lives left."<<endl; | |
} | |
} | |
if(g == 2) | |
{ | |
cout<<"what is 6 x 5"<<endl; | |
cin>> answer; | |
if(answer == "30") | |
{ | |
//SetConsoleTextAttribute(hConsole,2) | |
cout<<"Correct"<<endl; | |
//SetConsoleTextAttribute(hConsole,7) | |
} | |
else | |
{ | |
//set console attribute(hConsole,4) | |
cout<<"Incorrect"<<endl; | |
//SetConsoleTextAttribute(hConsole,7) | |
health = health-1; | |
cout<<"you have "<< | |
health<< | |
" lives left."<<endl; | |
} | |
} | |
if(g == 3) | |
{ | |
cout<<"what is 7 x 5"<<endl; | |
cin>> answer; | |
if(answer == "35") | |
{ | |
//SetConsoleTextAttribute(hConsole,2) | |
cout<<"Correct"<<endl; | |
//SetConsoleTextAttribute(hConsole,7) | |
} | |
else | |
{ | |
//set console attribute(hConsole,4) | |
cout<<"Incorrect"<<endl; | |
//SetConsoleTextAttribute(hConsole,7) | |
health = health-1; | |
cout<<"you have "<< | |
health<< | |
" lives left."<<endl; | |
} | |
} | |
if(g == 4) | |
{ | |
cout<<"what is 8 x 5"<<endl; | |
cin>> answer; | |
if(answer == "40") | |
{ | |
//SetConsoleTextAttribute(hConsole,2) | |
cout<<"Correct"<<endl; | |
//SetConsoleTextAttribute(hConsole,7) | |
} | |
else | |
{ | |
//set console attribute(hConsole,4) | |
cout<<"Incorrect"<<endl; | |
//SetConsoleTextAttribute(hConsole,7) | |
health = health-1; | |
cout<<"you have "<< | |
health<< | |
" lives left."<<endl; | |
} | |
} | |
if(g == 5) | |
{ | |
cout<<"what is 9 x 5"<<endl; | |
cin>> answer; | |
if(answer == "45") | |
{ | |
//SetConsoleTextAttribute(hConsole,2) | |
cout<<"Correct"<<endl; | |
//SetConsoleTextAttribute(hConsole,7) | |
} | |
else | |
{ | |
//set console attribute(hConsole,4) | |
cout<<"Incorrect"<<endl; | |
//SetConsoleTextAttribute(hConsole,7) | |
health = health-1; | |
cout<<"you have "<< | |
health<< | |
" lives left."<<endl; | |
} | |
} | |
} | |
} | |
cout<<"Game over " << playername << " would you like to start again. Type yes to coninue and anything else to quit"<<endl; | |
string response; | |
cin>> response; | |
if(response == "yes") | |
{ | |
goto label1; | |
} | |
else | |
{ | |
return 0; | |
} | |
return 0; | |
} |