Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions