FINAL PROJECT NEED HELP | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

FINAL PROJECT NEED HELP

Hello guys, I have two issues, for one, I have been trying to fix my program so that if a wrong symbol is placed in by the user it would end the program entirely but only place in both "cout << "SORRY, PLEASE ONLY ENTER A SYMBOL LISTED ABOVE!";" and the while loop, because when, for example I put a exclamation mark instead of the symbols listed above it will still input the random numbers with that symbol and then affterrrr it would input the cout I typed above ^^, and two, when I actually do enter the right symbol and the right answer it would end the loop, only when I place an incorrect answer would it let me re run the program? what am i doing wrong??? thank you in advanced! // Created by Gabriel Reyes //C++ Program FINAL PROJECT //Gabriel Reyes, February 5, 2022 CIS-5 #include <iostream> #include <cmath> #include <ctime> //v1.2 using namespace std; int main() { char programerChoice = 'y'; do { srand(time(NULL)); //v1.2 char sym_choice; //Symbol Choice int one, two; char A_WAIT; //Answer to match with already generated problem cout << "\tHello, please Select A symbol to\n"; cout << "\tsolve a random math problem: \n"; cout << "\t(+,-,*,/)\n\n"; cout << "\tENTER YOUR CHOICE: "; cin >> sym_choice; // if (sym_choice == ('+'|| '-'|| '*'|| '/')) int answer = 0; bool CORRECT = false; one = rand() % 500 + 1; two = rand() % 500 + 1; std::cout << "What is " << one << " " << sym_choice << " " << two << "? "; cin >> A_WAIT; switch (sym_choice) { case '+': answer = one + two; CORRECT = true; break; case '-': answer = one - two; CORRECT = true; break; case '*': answer = one * two; CORRECT = true; break; case '/': answer = one / two; CORRECT = true; break; default: { cout << "SORRY, PLEASE ONLY ENTER A SYMBOL LISTED ABOVE!"; return 1; } } if (CORRECT == true) { cout << answer << "\n\nIf your Answer Matches then Nice job!" << endl; }

9th Feb 2022, 2:38 AM
Gabriel Reyes
4 Réponses
+ 3
Gabriel , Right now, you need something like this at the end of your code: }while(some condition);} Since you used a do, but a while is missing you should use the playground and insert a link to your code, to make it easier to help you, next time: https://code.sololearn.com/ccHgLV7PFCIu/?ref=app
9th Feb 2022, 3:06 AM
CGM
CGM - avatar
+ 3
Why did you stretch your code so much, or do you think the more lines the better? As far as I understand, he did not even fit entirely in your question. No end of do... while loop; no end of main() function; variables programerChoice and A_WAIT are not used. And a separate question: "why do you need curly braces in default?" And take the variables initialization out of the loop.
9th Feb 2022, 4:00 AM
Solo
Solo - avatar
+ 2
Hey you are not checking if user entered right answer or not. You are checking only for right symbol,. So fix this first.... You should check at last if(answer == A_WAIT)...
9th Feb 2022, 2:53 AM
saurabh
saurabh - avatar
+ 1
Thank.... you.... gonna change my code up i might have to reformat the whole thing, bummer, it doesnt take long but when you have ADHD.. oh boy
9th Feb 2022, 3:20 AM
Gabriel Reyes