+ 1

FINAL PROJECT

Hello, I have already completed this program, it runs as I want it to, however I would like to use while so it gives the user a chance to press "Y" in order to re run the program instead of having to restart it entirely, can I please get help? sorry if this seems too easy it is my first program and C++ is a PAIN FOR MEEE! //C++ Program FINAL PROJECT //Gabriel Reyes, February 5, 2022 CIS-5 #include<iostream> #include<cmath> #include<ctime> //v1.2 using namespace std; int main() { srand(time(NULL)); //v1.2 char sym_choice; //Symbol Choice int one, two; char A_WAIT; //Answer to match with already generated problem char programerChoice; 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; } cout << "Press 'Y or y' for repeat again, otherwise press any character: "; cin >> programerChoice; while (

7th Feb 2022, 1:16 AM
Gabriel Reyes
7 Réponses
+ 5
Your code is incomplete. Save it in the code playground and share it's link here. To accomplish this, you can enclose your whole main block inside a while loop with condition (choice=='Y'). And yeah, don't forget to get the user choice as input at the end of the main block
7th Feb 2022, 2:22 AM
Rishi
Rishi - avatar
+ 4
Gabriel Reyes I've used a do while loop to accomplish this, have a look at the code below. If you get any doubts regarding this, ping me https://code.sololearn.com/cvh3zn4EwJWD/?ref=app
7th Feb 2022, 2:39 AM
Rishi
Rishi - avatar
+ 4
Gabriel Reyes I suppose you wanted to use the do...while loop, but missed the "do" block. Anyway, happy to help 🙂
7th Feb 2022, 3:53 AM
Rishi
Rishi - avatar
+ 3
it works! i actually tried the same thing, i must have missplaced something, but thank you so much!!
7th Feb 2022, 2:42 AM
Gabriel Reyes
7th Feb 2022, 2:27 AM
Gabriel Reyes
+ 1
Francisco Fernandez only post answers, don't share others' code here
8th Feb 2022, 2:35 AM
Rishi
Rishi - avatar
8th Feb 2022, 2:34 AM
Francisco Fernandez