The sum of two numbers

closed account (ENh0ko23)
I am writing an if else statement where i need to see if the sum of two numbers in equal to, greater than or less than 100. I put in this code down below, and when i compile it , it shows two of the statements.





1
2
3
4
5
6
if (a + b > 100)
		cout << "The sum of these numbers is less than 100." << endl;
	if (a + b == 100)
		cout << "The sum of these numbers is equal to 100." << endl;
	else
		cout << "The sum of these numbers is greater than 100." << endl;
-
Last edited on
Except that the logic is backwards :+)

1
2
3
        if (a + b > 100) {
		cout << "The sum of these numbers is less than 100." << endl;
        }


Always uses braces, even if there is only one statement.
Last edited on
@joe864864, i think you missed < for >

1
2
3
4
5
6
7
8
9
10
11
12
13
       if ((a + b) < 100)
         {
            cout << "The sum of these numbers is less than 100." << endl;
         }
		
	else if ((a + b) == 100)
	 {
             cout << "The sum of these numbers equal to 100." << endl;
         }
	else
          {
               cout << "The sum of these numbers is greater than 100." << endl;
          }

Last edited on
Topic archived. No new replies allowed.