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
#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
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started