12,762,900 members (34,994 online)
Rate this:
See more:
I'm writing a code that will take three numbers as input and determine whether
"SUM OF ANY TWO NUMBERS" is greater then third number..
The output is annoying me. . . if u put A=1, B=1, C=2

```#include <iostream>

using namespace std;

int main(int A, int B, int C)
{
cout << "To Check The Sum Of Two Number Is Greater" << endl
<< "Enter A Integer" << endl; cin >> A;
cout << "Enter B Integer" << endl; cin >> B;
cout << "Enter C Integer" << endl; cin >> C;

if(A+B>C)
{
if(B+C>A)
cout << "Sum Of B & C Is Greater Then A" << endl;
}
else
cout << "Sum Of A & B Is Greater Then C" << endl;
{
if(C+A>B)
cout << "Sum Of C Is Greater Then B" << endl;
}
return 0;
}```
Posted 20-Nov-12 9:51am
ctype.h1.5K
Sergey Alexandrovich Kryukov 20-Nov-12 14:55pm

First of all, stop passing A, B, C as parameters... it looks like you don't know what a parameter is for, and how the entry point "main" should look... Learn it and come back.
And do you know what a function is? Create another function for this calculation...
--SA
Albert Holguin 20-Nov-12 15:05pm

What's the problem? ....you have no problem statement or question.
Scenic Design 20-Nov-12 15:58pm

Yes Sir actually I'm a student of BS(Computer Science) and new in C++ ..
But I think I'm gona learn a lot from here . . .

Rate this:

## Solution 1

You really need to review the syntax of `if` blocks. My first recommendation is to always use curly braces (i.e. { } ) for your `if` blocks (and loops as well). While it's not required for ones that contain a single line of statements in them, it makes it a lot easier to see what's going on, and easier to edit later if you decide to add more statements.

And yes, this is relevant, because right off the bat I notice a problem here:
```else
cout << "Sum Of A & B Is Greater Then C" << endl;
{
if(C+A>B)
cout << "Sum Of C Is Greater Then B" << endl;
}```

This probably doesn't do what you intended. If the `else` part is reached, then the line immediately after it is executed. Then you are no longer in the `else` block. The following `if` statement will always be executed, because it is not attached to the `else`, you have just created it in a different scope.

I'm not entirely sure what you meant to do there, but start by looking at that point.
Scenic Design 20-Nov-12 16:00pm

Rate this:

## Solution 2

Your brackets are wrong on your if statements. For example, the very first evaluation is "if A+B is greater than C" then you will enter the first brackets below that... getting to the "if B+C is greater than A" statement. Fine... except that if B+C is greater than A, you are outputting the statement. But if it isn't, you are doing nothing... there is no else (false) condition defined so you not print anything. If I made A=3, B=0, and C=2, I would get nothing back as the output.

Further, on your outer if you have an else but it isn't bracketed properly. Only the cout statement is part of that else logic. The brackets that follow it mean nothing... that code will get executed just as if the brackets weren't there. If I made A=2, B=3, and C=2 I would get "Sum Of A & B Is Greater Then C" followed by "Sum Of C Is Greater Then B"... I'm guessing this isn't what you want.

If statements look like:

```if (true/false evaluation)
{
// True Part
}
else
{
// False Part
}```

Good luck. And yes... you shouldn't pass in the variables as parameters to main.
Scenic Design 20-Nov-12 16:03pm

Exactly Sir. . .

Top Experts
Last 24hrsThis month
 Peter Leow 160 OriginalGriff 145 ppolymorphe 140 CPallini 105 Karthik Bangalore 100
 OriginalGriff 4,787 Peter Leow 3,554 ppolymorphe 2,923 Karthik Bangalore 2,814 Graeme_Grant 2,626