May 2021 2 54 Report
How to exit a program with system("pause") ?

include <iostream>

#include <cmath>

using namespace std;

int main()

{

double a, b, c, r1, r2, disc;

cout << "Please enter three number:";

cin >> a >> b >> c;

if (( a == 1 || a == -1 || a == 2) && (b >= -2 && b<=5) && (c>= -4 && c <= 4)){

cout << endl << endl;}

else

cout << endl << "Please exit program and re-enter new number" << endl << endl; // Exit program if this output display.

system("pause");

cout << "\n" << "a" << "\t" << "b" << "\t" << "c" << endl << "\n" ;

cout << a << "\t" << b << "\t" << c << endl << "\n";

cout.setf(ios::fixed,ios::floatfield);

cout.precision(3);

disc = sqrt (pow (b,2) - (4.0 * a * c));

cout << endl << "Discriminate" << endl << endl << disc << endl << endl;

r1 = ((-b + disc ) / (2.0*a));

r2 = ((-b - disc ) / (2.0*a));

if (disc >= 0) {

cout << "Root 1" << "\t" << "Root 2" << endl << endl;

cout << r1 << "\t" << r2; }

else

cout << "No Solution";

cin >> r1 >> r2 >> disc;

return 0;

}

How to make the program exit by itself when a, b, and c is not equal to the variable I declared?

If I put a pause, it will stop the program from running to the next if statement, however, if a,b, and c is the correct variable, it will also pause. So I find it impractical. Is there a way to make it exit when a,b, and c is not equal to the variable I declared and run the entire program if a, b, and c is the correct variable?

Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Helpful Social

Copyright © 2024 QUIZLS.COM - All rights reserved.