#include <iostream>
#include <cmath>
usingnamespace std;
int main()
{
int sum;
int diff;
int prod;
int div;
int power;
int quit;
int ans;
int y;
int z;
int remain;
double real;
int choice;
cout << "Enter the first operation type (sum, diff, prod, div, power, or quit): ";
cin >>choice;
while (choice!=quit)
{
cout << "Enter the first (integer) number: ";
cin >> y;
cout << "Enter the second (integer) number: ";
cin >> z;
if (choice==sum)
{
ans = y + z;
cout << "The sum is " << ans << endl;
}
elseif (choice==diff)
{
ans = y - z;
cout << "The difference is " << ans << endl;
}
elseif (choice==prod)
{
ans = y * z;
cout << "The product is " << ans << endl;
}
elseif (choice==div)
{
ans = y / z;
remain = y % z;
real = y / z;
cout << "The quotient is " << ans << endl
<< "The remainder is " << remain << endl
<< "The real quotient is " << real << endl;
}
elseif (choice==power)
{
ans = (int) pow((double) y, z);
cout << "The power is " << ans << endl;
}
elseif (choice==quit)
{
return 0;
}
else
cout << "invalid operation code";
cout << "Enter the operation type (sum, diff, prod, div, pow, or quit): ";
cin >> choice;
}
}
------------------------------------
Ignore the whole sum = 1 stuff....
I had it as while (choice=!quit) and if (choice==sum) etc. but they keep throwing me into an infinite loop where it asks for the first (integer) number.
What about the format of the loop is set up wrong?
How do I set the conditions of the "else if" statements properly?
I updated the post with what I have now. Needing choice again at the end makes sense, so I put that in.
But, why does my program not pause for inputting of the two integer numbers?
The way it is now, it asks for the operation type, and if I put in " sum " then it goes through "enter first number: enter second number: invalid operation code"
and quits.
I am supposed to use the if/else loop method in this assignment.
I don't understand what you mean, helios. What can I do about it not stopping for input, and not recognizing when I put "sum" to go to the sum part of the loop?
I was forced to submit this, but please someone tell me how it could have been fixed for future reference. I know it has to be something minor because all of it makes sense other than it not recognizing to go to the proper function.