So I did this....

#include <iostream>

using namespace std;

int main() {

int x = 240;
int y = 463;
int total = x + y;

x = x + 3;

cout << "The Value of x: " << x << endl;
cout << "The Value of y: " << y << endl;
cout << "Total of x, y: " << total << endl;

return 0;

}

Console:
The Value of x: 243
The Value of y: 463
Total of x, y: 703

===================
Question: Why is the Total 703?
But I want to make 240 to 243 but why the total is not responding?
total won't change if you change x or y. It'll add the numbers and store the result in total. Changes made to x or y after that point won't have an effect on total
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

using namespace std;

int main() {

   int x = 240;
   int y = 463;
   int total = x + y; // total = 240 + 463 = 703

   x = x + 3; // x = 240 + 3 = 243

   cout << "The Value of x: " << x << endl; // x = 243
   cout << "The Value of y: " << y << endl; // y = 463
   cout << "Total of x, y: " << total << endl; // total = 703

   return 0;

}
closed account (48T7M4Gy)
But I want to make 240 to 243 but why the total is not responding?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

using namespace std;

int main() {

   int x = 240;
   int y = 463;
   int total = x + y; // total = 240 + 463 = 703

   x = x + 3; // x = 240 + 3 = 243
   total = x + y // total = 243 + 463 = 706

   cout << "The Value of x: " << x << endl; // x = 243
   cout << "The Value of y: " << y << endl; // y = 463
   cout << "Total of x, y: " << total << endl; // total = 706

   return 0;

}
Topic archived. No new replies allowed.