diff --git a/main.cxx b/main.cxx index 7f949a0..a227205 100644 --- a/main.cxx +++ b/main.cxx @@ -3,185 +3,190 @@ #include #include #include +#include +#include using namespace std; -static int wrongAns = 0, correctAns = 0; -double answer, marks; -int numberOfQuestions, choice, schoice, set_choice, logo, theme; -bool mixed = false; +int numberOfQuestion,correct_count = 0, wrong_count = 0; +float marks; +char operators[] = {'+','-','*','/'}; string name; -//displays when answer is wrong -void Wrong() { +float divisionAns(int,int); +void startGame(); +void loading(); +void questionsGenerator(int); +void answerChecker(int,char,int,float); +void Correct(); +void Wrong(); - cout <<" WRONG" << endl; - wrongAns++; +int main(){ + startGame(); + return 0; +} + +void answerChecker(int a,char b,int c,float d){ + switch(b){ + case '+':{ + if(d == (a + c)){ + Correct(); + } + else{ + Wrong(); + } + break; + } + case '-':{ + if(d == (a - c)){ + Correct(); + } + else{ + Wrong(); + } + break; + } + case '*':{ + if(d == (a * c)){ + Correct(); + } + else{ + Wrong(); + } + break; + } + case '/':{ + if(d == divisionAns(a , c)){ + Correct(); + } + else{ + Wrong(); + } + break; + } + } + +} +//displays when answer is wrong +void Wrong() { + cout <<" WRONG" << endl; + wrong_count++; } //displays when answer is correct void Correct() { - cout <<" CORRECT" << endl; - - correctAns++; + correct_count++; } //sets the quotient into having two decimal places -float round(float var ){ - - float value = (int)(var * 100 + .5); - - return (float)value / 100; +float divisionAns(int dividend,int divider){ + return static_cast(dividend) / divider; } + //the loading screen void loading() { - cout<= 1; j--) { cout <(correct_count) / numberOfQuestion) * 100; + cout << "Marks are: " << marks << "%" << endl; + cout<<"---------------------------------------"<> play_again; - cout<<"---------------------------------------"<>schoice; - - switch(schoice) { - + cout << "1.start\n"; + cout << "2.settings\n"; + cout << "3.Exit\n"; + cout << endl; + cout << "CHOICE: "; + cin >> menu_choice; + switch(menu_choice) { case 1: { - cout << "Enter your name: "; - cin >> name; - cout << endl; - cout << "Enter the number of questions: "; - - cin >> numberOfQuestions; - + cin >> numberOfQuestion; cout << endl; - cout << "CHOOSE THE TYPE OF QUESTION:" << endl; - cout << endl; - - cout << "1.Addition" << endl; - - cout << "2.Subtraction" << endl; - - cout << "3.Multiplication" << endl; - - cout << "4.Division" << endl; - - cout << "5.Mixed" << endl; - + cout << "1.Addition\n"; + cout << "2.Subtraction\n"; + cout << "3.Multiplication\n"; + cout << "4.Division\n"; + cout << "5.Mixed\n"; cout << endl; - cout << "CHOICE: "; - - cin >> choice; - - switch (choice) { - - case 1: { - - loading(); - - char sign = '+'; - - questions(sign); - - break; - } - case 2: { - - loading(); - - char sign = '-'; - - questions(sign); - - break; - - } - - case 3: { - - loading(); - - char sign = '*'; - - questions(sign); - - break; - } - case 4: { - - - - loading(); - - char sign = '/'; - - questions(sign); - - break; - } - case 5: { - - loading(); - - mixed = true; - - char sign = 'm'; - - questions(sign); - - break; - - } - default: { - - cout << "invalid option" << endl; - - } - } - - char playAgain; - - cout << "Do you want to play again? (y/n): "; - - cin >> playAgain; - - if (playAgain == 'y' || playAgain == 'Y') { - - wrongAns = 0; - - correctAns = 0; - - system("cls"); - - startGame(); - - } else { - - - - cout << "Thanks for playing!" << endl; - } + cin >> operation_choice; + loading(); + questionsGenerator(operation_choice); break; } - case 2: { - + + case 2:{ + back_settings: system("cls"); - - cout<<"settings"<>set_choice; - - switch(set_choice) { - + cout << "settings\n"; + cout << "--------\n"; + cout << "1.Theme\n"; + cout << "2.Credits\n"; + cout << "CHOICE: "; + cin >> settings_choice; + switch(settings_choice) { case 1: { - - system("cls"); - - cout<<"choose theme:\n"; - cout<<"1.Dark theme:\n"; - - cout<<"2.Light theme:\n"; - - cout<>theme; - - - + cout << "choose theme:\n"; + cout << "1.Dark theme:\n"; + cout << "2.Light theme:\n"; + cout << endl; + cout << "CHOICE: "; + cin >> theme; switch(theme) { - case 1: { - system("color 0F"); - system("cls"); - startGame(); - break; } + case 2: { - system("color F0"); - system("cls"); - startGame(); - break; } } break; } + case 2:{ - - cout<<"HELLO WORLD!"; + system("cls"); + cout << "MADE BY ADON TUMAINI\n"; + cout << "hope you enjoy it :)"; + system("pause"); + startGame(); + break; + } + + default:{ + cout << "invalid choice\n"; + system("pause"); + goto back_settings; break; } - break; - } - + break; + } + case 3:{ + exit(0); + break; + } + + default:{ + cout << "invalid choice\n"; + system("pause"); + system("cls"); + startGame(); + break; } - } } - - -int main() { - - startGame(); - - return 0; -}