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?
Copyright © 2024 QUIZLS.COM - All rights reserved.
Answers & Comments
Verified answer
If your if statement isn't true, then you want to do 3 different things in your else part, right?
You want to:
Print an error message.
Run Pause
Exit the program.
When you need to do more than 1 thing in the if or else part of an if/else, you need to put braces around the code. (Actually, it is good practice to ALWAYS put in the braces, even if you are only doing 1 thing).
So, you add the braces:
else
{
}
Then you fill in what you need to do:
else
{
cout << endl << "Please exit program and re-enter new number" << endl << endl;
system("pause");
return 1;
}
Note: You could also use return 0, but it is a good idea NOT to return 0 when the program fails. 0 traditionally means SUCCESS.
i might want to help it. i'm a Liberal yet i don't love the actual undeniable actuality that an excellent form of authorities spending isn't being positioned to artwork. would not advise i want to restrict the equipment thoroughly. right that's my concept. in case your positioned on welfare, then you particularly ought to affix some form of educating or locate a commerce. interior of two-3 years you need to be able end the training or the commerce. when they are performed with the training/commerce they have up till a a million to locate a interest and develop into independent on welfare. There are human beings on welfare who particularly want it and there are those who abuse the equipment it really is unlucky. truly of throwing money out to human beings we'd like to make positive that we are doing some thing which will earnings them contained in the destiny and by no potential only for months at a time.