// H2.cpp : Tihs program runs different mathmatical operations on numbers given by the user
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int a;
cout << "Enter a number for a: "; //Prompts the user for a and b inputs
cin >> a;
int b;
cout << "Enter a number for b: ";
cin >> b;
cout << "A is " << a << "\tB is " << b << endl;
cout <<"Sum of a and b is equal to " << a << " + " << b << " and the result is " << (a + b) << endl; //Performs addition operator and gives output
cout <<"Product of a and b is equal to " << a << " * " << b << " and the result is " << (a * b) << endl;
cout <<"a > b is " << a << " > " << b << " and the result is " << (a > b) << endl;
cout <<"a < b is " << a << " > " << b << " and the result is " << (a < b) << endl;
cout <<"a == b is " << a << " == " << b << " and the result is " << (a == b) << endl; //Performs boolean operator and outputs result
cout <<"a >= b is " << a << " >= " << b << " and the result is " << (a >= b) << endl;
cout <<"a <= b is " << a << " <= " << b << " and the result is " << (a <= b) << endl;
cout <<"a != b is " << a << " != " << b << " and the result is " << (a != b) << endl;
cout <<"a -= b is " << a << " -= " << b << " and the result is a = " << (a -= b) << endl; //Performs - operator on a - b and makes a equal to the new result
cout <<"a /= b is " << a << " /= " << b << " and the result is a = " << (a /= b) << endl;
cout <<"a %= b is " << a << " %= " << b << " and the result is a = " << (a %= b) << endl; //Performs % operator on a % b and makes a equal to the new result. Ripple effect created from previous 2 lines as the value of a changes each time.
return 0;
The output I'm concerned with is here:
a -= b is -4198672 -= 4198672 and the result is a = -4198672
a /= b is -1 /= 4198672 and the result is a = -1
a %= b is -1 %= 4198672 and the result is a = -1
It seems like the value for a being displayed is the value of a after the line of code is executed. I'm sure that has something to do with the order of operations, but I'm not sure how to get around that. Any help is greatly appreciated.