From 9ad3f3143383d0e7791899c10770a560a3229081 Mon Sep 17 00:00:00 2001 From: apexo9 Date: Mon, 4 Aug 2025 23:39:32 -0700 Subject: [PATCH 1/2] Update main.cxx updated --- main.cxx | 498 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 268 insertions(+), 230 deletions(-) diff --git a/main.cxx b/main.cxx index 7f949a0..e9827db 100644 --- a/main.cxx +++ b/main.cxx @@ -1,23 +1,88 @@ #include + #include + #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; +float divisionAns(int,int); +void startGame(); +void loading(); +void questionsGenerator(int); +void answerChecker(int,char,int,float); +void Correct(); +void Wrong(); + + +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; - wrongAns++; + wrong_count++; } @@ -26,17 +91,15 @@ 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() { @@ -63,117 +126,122 @@ void loading() { } //generates questions based on operation chosen -void questions(char oper) { - - for (int k = 1; k <= numberOfQuestions; k++) { - - if(mixed == true){ - char mixed_sign[] = {'+','-','/','*'}; - - int operatorIndex; - - operatorIndex = 0 + rand() % 4; - - oper = mixed_sign[operatorIndex]; +void questionsGenerator(int operation) { + + char sign,play_again; + + int first_value,second_value,answer; + + switch(operation){ + + case 1:{ + + sign = '+'; + + break; } + + case 2:{ + + sign = '-'; + + break; + } + + case 3:{ + + sign = '*'; + + break; + } + + case 4:{ + + sign = '/'; + + break; + } + + case 5:{ + + operation = 5; + + break; + } + + default:{ + + cout << "invalid option"; + + break; + } + } + for (int k = 1; k <= numberOfQuestion; k++) { - int firstValue = 51 + rand() % 50; - int secondValue = 1 + rand() % 50; + first_value = 50 + rand() % 100; + + second_value = 1 + rand() % 100; + cout << endl; - cout << "QN" << ":" << firstValue<<" "<< oper<<" "<(correct_count) / numberOfQuestion) * 100; cout << "Marks are: " << marks << "%" << endl; cout<<"---------------------------------------"<> play_again; + + if( play_again == 'y' || play_again == 'Y'){ + + startGame(); + } + + else{ + + exit(0); + + } } +} //game starts here -void startGame() { +void startGame(){ - mixed = false; + int menu_choice,operation_choice,settings_choice,theme,logo; srand(time(0)); @@ -182,6 +250,7 @@ void startGame() { logo=1+rand()%3; if(logo==1) { + cout << "aaaaaaaaaaaaaaa aaaaaaaaaaaaaaa " << endl; cout << "aaaaaaaaaaaaaaa aaaaaaaaaaaaaaa " << endl; cout << "aaaaa aaaaa aaaaa " << endl; @@ -191,7 +260,9 @@ void startGame() { cout << "aaaaa aaaaa aaaaa " << endl; cout << "aaaaa aaaaa aaaaaaaaaaaaaaa " << endl; cout << "aaaaa aaaaa aaaaaaaaaaaaaaa " << endl; + } else if(logo==2) { + cout<<"############### ##### ##### ############### "<>schoice; + cin >> menu_choice; - switch(schoice) { + switch(menu_choice) { case 1: { @@ -240,7 +317,7 @@ void startGame() { cout << "Enter the number of questions: "; - cin >> numberOfQuestions; + cin >> numberOfQuestion; cout << endl; @@ -248,146 +325,68 @@ void startGame() { cout << endl; - cout << "1.Addition" << endl; + cout << "1.Addition\n"; - cout << "2.Subtraction" << endl; + cout << "2.Subtraction\n"; - cout << "3.Multiplication" << endl; + cout << "3.Multiplication\n"; - cout << "4.Division" << endl; + cout << "4.Division\n"; - cout << "5.Mixed" << endl; + 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; + cin >> operation_choice; - 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; - } + loading(); + + questionsGenerator(operation_choice); + break; + } - case 2: { - + + case 2:{ + + back_settings: + system("cls"); - - cout<<"settings"<>set_choice; - - switch(set_choice) { + + back: + + 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 << "choose theme:\n"; + + cout << "1.Dark theme:\n"; - cout<<"2.Light theme:\n"; + cout << "2.Light theme:\n"; - cout<>theme; + cin >> theme; @@ -412,29 +411,68 @@ void startGame() { 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; -} From bff8e25ecb956620a2a481e2e40391a0c7e0903b Mon Sep 17 00:00:00 2001 From: Project-Sigma25 Date: Mon, 11 Aug 2025 07:29:25 -0700 Subject: [PATCH 2/2] Update main.cxx remove blank lines and fixed the play_again part --- main.cxx | 209 ++++++++----------------------------------------------- 1 file changed, 30 insertions(+), 179 deletions(-) diff --git a/main.cxx b/main.cxx index e9827db..a227205 100644 --- a/main.cxx +++ b/main.cxx @@ -1,15 +1,9 @@ #include - #include - #include - #include - #include - #include - #include using namespace std; @@ -29,9 +23,7 @@ void Wrong(); int main(){ - startGame(); - return 0; } @@ -79,18 +71,13 @@ void answerChecker(int a,char b,int c,float d){ //displays when answer is wrong void Wrong() { - cout <<" WRONG" << endl; - wrong_count++; - } //displays when answer is correct void Correct() { - cout <<" CORRECT" << endl; - correct_count++; } @@ -102,151 +89,100 @@ float divisionAns(int dividend,int divider){ //the loading screen void loading() { - cout<= 1; j--) { cout <(correct_count) / numberOfQuestion) * 100; - - cout << "Marks are: " << marks << "%" << endl; - - cout<<"---------------------------------------"<> play_again; - - if( play_again == 'y' || play_again == 'Y'){ - - startGame(); - } + cout<<"---------------RESULTS-----------------"<(correct_count) / numberOfQuestion) * 100; + cout << "Marks are: " << marks << "%" << endl; + cout<<"---------------------------------------"<> play_again; - else{ - - exit(0); - - } - -} + if( play_again == 'y' || play_again == 'Y'){ + system("cls); + startGame(); + } + else{ + exit(0); + } + + } } //game starts here void startGame(){ - int menu_choice,operation_choice,settings_choice,theme,logo; - srand(time(0)); - cout << endl; - logo=1+rand()%3; if(logo==1) { @@ -261,7 +197,9 @@ void startGame(){ cout << "aaaaa aaaaa aaaaaaaaaaaaaaa " << endl; cout << "aaaaa aaaaa aaaaaaaaaaaaaaa " << endl; - } else if(logo==2) { + } + + else if(logo==2) { cout<<"############### ##### ##### ############### "<> menu_choice; - switch(menu_choice) { - case 1: { - cout << "Enter your name: "; - cin >> name; - cout << endl; - cout << "Enter the number of questions: "; - cin >> numberOfQuestion; - cout << endl; - cout << "CHOOSE THE TYPE OF QUESTION:" << endl; - cout << 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 >> operation_choice; - loading(); - questionsGenerator(operation_choice); - break; - } case 2:{ - back_settings: - system("cls"); - - back: - 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 << 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:{ - 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:{ - + case 3:{ exit(0); - break; } default:{ - cout << "invalid choice\n"; - system("pause"); - system("cls"); - startGame(); - break; } - } }