Programme always give wrong answer.

#include <iostream.h>
#include <conio.h>

// I made this simple programme but it always give wrong answer. Dont know what to do. Whatever values of a and b I put. It will always give 4265633.

// P.S I'm new to C++

void main()

{

int a,b,c;
c=a+b;

cin>>a;
cin>>b;
cout<<c;

getch();

}
Last edited on
This should go in the Beginners section.

#include <iostream.h>
You're using an old compiler, probably Turbo C++. There's simply no excuse to use such old and increasingly irrelevant tools.

You should declare variables where they're used. Your actual error is, you're calculating c before a and b are assigned values.
1
2
3
4
5
6
7
8
9
int main()
{
    int a,b;
    cin>>a;
    cin>>b;

    int c = a+b;
    cout<<c;
}
Oh! It worked.Thank you so much. So kind of you to reply a noob like me :)
I just started learning a few days ago.

Btw where is the beginners forum?
http://www.cplusplus.com/forum/beginner/

Please move this thread there.

You move a thread by clicking Edit on the first post, then selecting a different subforum, in this case Beginners.
Ok. Thank you !
Topic archived. No new replies allowed.