// 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;
私が懸念している出力は次のとおりです。
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
表示されている a の値は、コード行が実行された後の a の値のようです。それは操作の順序と関係があると確信していますが、それを回避する方法がわかりません。どんな助けでも大歓迎です。