Hello,about addition...

Hello,When I enter the number a and b, it just prints the value of b and won't add a and b together to c,where's the problem?
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
#include <iostream>

using namespace std;

int main()
{
    int a,b,c;

    cout << "Enter a:";
    cin >> a;

    cout << "Enter b:";
    cin >> b;

    c = a+b;

    cout << "Addition:" << b << endl;


if (c > 50)
    cout << "Number is higher than 50" << endl;
else
    cout << "Number is lower than 50" << endl;




return 0;

}
cout << "Addition:" << b << endl;

You told it to print out b. Change that to c.
It will produce fictitious results with c is equal to 50.

Boundary conditions like this will always screw-up the best programmers.

- - --- -- -- --
The other thing which will always foil a good programmer is when she or he
uses variable names that don't describe the TYPE or the REASON for their existence; at least they could be i_a, i_b, & i_c ( or i_result)
- just saying.


Last edited on
Topic archived. No new replies allowed.