#include <iostream>
#include <windows.h>
#include <cstdlib>
#include <ctime>
#include <cstdlib>
#include <mmsystem.h>
#include <vector>
#include <conio.h>
#include <functional>
#include <stdio.h>
using namespace std;
char option;
int answer;
string theQues;
string theAns;
string ans;
void Start();
void Level1();
void Level2();
//oid Level3();

int point=4;

int main()
{


// system("color CE");
cout<<"\t** ** **** ****** ** ** **** **** ***"<<endl;
cout<<"\t*** *** ****** ****** ** ** ** ** ** ** *****"<<endl;
cout<<"\t** * ** ** ** ** ****** ***** ***** ** ** "<<endl;
cout<<"\t** * ** ****** ** ****** **** **** ** **"<<endl;
cout<<"\t** ** ****** ** ** ** ** ** ** ** **"<<endl;
cout<<"\t** ** ** ** ** ** ** ** ** ** *****"<<endl;
cout<<"\t** ** ** ** ** ** ** ** ** ** ***"<<endl;


cout<<"\n\n"<<endl;
cout << "\t.........HELLO WELCOME TO BE A MATH PRO!!!!!................. " << endl;
cout << "\t.........THIS GAME CONSIST OF THREE(3) LEVELS................"<< endl;
cout << "\t.........FOR YOU GET PAST THE FIRST LEVEL YOU NEED .......... "<< endl;
cout << "\t.........TO ACHIEVE A SCORE OF OVER 75% !!!.................. \n\n\n\n\n"<< endl;

Start();
return 0;
}


void Start(){
// int Number;

cout<< "\tAre you ready to start(y/n): ";
cin>> option;
if(option=='y'||option=='Y'){

system("cls");

Level1();
}
else{
exit(0);
}

}


void Level1(){


float grade=0;
float score;
PlaySound("C:/Users/Orrett/Desktop/Games Programing/Math pro game/SoundTrack.wav",NULL,SND_FILENAME|SND_LOOP|SND_ASYNC);
enum fields {QUESTION, ANSWER, NUM_FIELDS};
const int QUEST= 4;
vector<int> exist;

const string QUESTIONS[QUEST][NUM_FIELDS]=
{
{"21 x 4= _ ", "84"},
{"74.5 - 21.9=_ ", "52.6"},
{"72 / 6=_ ", "12"},
{"200 + 39.5=_ ", "239.5"}
};
for(int i=0; i<4; i++){
srand(time(0));
int choice = (rand() % QUEST);

theQues= QUESTIONS[choice][QUESTION]; // Questions to Answer
theAns = QUESTIONS[choice][ANSWER];


exist.push_back(choice);
cout<< "Please solve the Following Problem :\n"<<endl;
if(choice == exist[choice]){

}
cout<< theQues;
cin>> ans;

if(ans== theAns){
cout<<"Thats Correct!!!\n\n"<<endl;
grade++;
}
else{
cout<<"Thats Incorrect!!!\n\n"<<endl;
}

}
score= (grade/point)*100;

cout<<"Your score is : "<< score<<"%"<<endl;
cout<<"\n\n\n\n"<<endl;
if(score>= 75 ){
cout<<"Great Job you can move to the next level\n\n\n\n"<<endl;
Sleep(5000);
system("cls");
Level2();
}
else

cout<<"Sorry you cant move on"<<endl;
cout<<"Do you want to try again? (y/n) ";
cin>> option;

if(option=='y'|| option=='Y'){
fflush(stdin);
system("cls");
Level1();
}
else
{
system("cls");
cout<<"Thanks for trying better luck next time!!!!"<<endl;
exit(0);

}
}

void Level2(){
float grade=0;
float score;
cout<<"WELCOME TO LEVEL 2"<<endl;
enum fields {QUESTION, ANSWER, NUM_FIELDS};
const int QUEST=4;
const string QUESTIONS[QUEST][NUM_FIELDS]=
{
{"x-11 = 36 x= ", "47"},
{"x+5=15 x= ", "10"},
{"25+ x= 52 x= ", "27"},
{"54-x= 24 x= ", "30"}
};
for(int i=0; i<4; i++){
srand(time(0));
int choice = (rand() % QUEST);
theQues= QUESTIONS[choice][QUESTION]; // Questions to Answer
theAns = QUESTIONS[choice][ANSWER]; // Matching Answers to the questions
cout<< "Please solve the Following Problem :\n"<<endl;
cout<< theQues;
cin>> ans;
if(ans== theAns){
cout<<"Thats Correct!!!\n\n"<<endl;
grade++;
}
else{
cout<<"Thats Incorrect!!!\n\n"<<endl;
}
}
score= (grade/point)*100;
cout<<"Your score is : "<< score<<"%"<<endl;
cout<<"\n\n\n\n"<<endl;
if(score>= 75){
cout<<"Great Good job you did well\n\n\n\n"<<endl;
Sleep(5000);
system("cls");
exit(0);
//Level2();
}
else
{
cout<<"Sorry you failed!!!!!"<<endl;
cout<<"Do you want to try again? (y/n) ";
cin>> option;

if(option=='y'|| option=='Y'){
system("cls");
Level1();
}
else
{
system("cls");
cout<<"Thanks for trying better luck next time!!!!"<<endl;
exit(0);
}
}
}
hardingC
Newbie Poster
Online
1 posts
since Nov 2011
Flag Bad Post Post Reply

Or (slightly more efficient if there are a fair number of questions) generate a random sequence to determine the order in whick questions are to be asked.

int random_sequence[QUEST] ;
for( int i=0 ; i<QUEST ; ++i ) random_sequence[i] = i ;
std::random_shuffle( random_sequence, random_sequence+QUEST ) ; // <algorithm>
for( int i=0 ; i<QUEST ; ++i )
{
     int choice = random_sequence[i] ;
     // ...
}
Comments
Excellent suggestion!

Or (slightly more efficient if there are a fair number of questions) generate a random sequence to determine the order in whick questions are to be asked.

int random_sequence[QUEST] ;
for( int i=0 ; i<QUEST ; ++i ) random_sequence[i] = i ;
std::random_shuffle( random_sequence, random_sequence+QUEST ) ; // <algorithm>
for( int i=0 ; i<QUEST ; ++i )
{
     int choice = random_sequence[i] ;
     // ...
}

Can u show me how you would implement this in my code

This article has been dead for over six months. Start a new discussion instead.