Question: My code works but won't exit when a user enters the letter q. How can I make it exit using c++ and my current code?

My code works but won't exit when a user enters the letter q. How can I make it exit using c++ and my current code? Also, please make program ask for input again if a big number like 5000000 is entered, so if the user enters 5000000, and at 1000000, they press the letter b, the programs stops computation and asks for input again?

#include #include #include #include

#define PI 3.14

using namespace std;

int main(){

// for the program to keepe executing until control + c is pressed, or 'q' is entered bool done = false;

while(!done){

std::cout << "Please enter an integer or 'q' to quit" << std::endl;

int input;

// get user input cin >> input;

std::cout << "You have asked to compute the square root of PI " << input << " times:" << std::endl;

// for loop to increment number output for(int i = 0; i < input; i++){ std::cout << (i+1) << std::endl; }

double calculatePi; calculatePi= sqrt(PI);

std::cout << "The square root of PI is " << setprecision(3) << calculatePi << "." << std::endl;

} }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!