Hi maroon419
Please always use code tags (the <> icon on the right of the text box), it makes it a lot easier for people to read your code.
A couple of things,
_Your code doesn't compile, you put semicolons after your if statements, that's not how they work, check the following link for more info:
https://en.cppreference.com/w/cpp/language/if
_You have too many if statements, and can easily group them (see my code below for example of that)
_Your mathematical logic is wrong, for multiplications and divisions:
*negative with negative gives positive
*positive with positive gives positive
*negative with positive gives negative
_To round your numbers, check the function
setprecision()
for which you included the right header
iomanip
:
http://www.cplusplus.com/reference/iomanip/setprecision/
Here is how you could have written your code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
int main()
{
double a,b;
cout << " Enter a: ";
cin >> a;
cout << " Enter b: ";
cin >> b;
cout << showpoint << setprecision(2) << fixed << "\n ";
if ( a != 0 && b != 0)
{
if (a > 0 && b > 0)
cout << b/a;
else if (a < 0 && b > 0)
cout << "-" << b/a;
else if (a > 0 && b < 0)
cout << "-" << b/a;
else if (a < 0 && b < 0)
cout << b/a;
}
else if ( a == 0 && b != 0 )
cout << "undefined";
else if ( a == 0 && b == 0)
cout << "indeterminate";
cout << "\n\n";
system("pause");
return 0;
}
|
Hope this helps you,
Regards,
Hugo.