# Thread: New to coding, needing some help.

1. ## New to coding, needing some help.

I'm new to coding and I'm trying to make a program that will simply add two numbers together and give an answer.

Code:
```#include <iostream>

using namespace std;

int main ()
{
float a, b, c;
c = a+b;

cin >>a>>b;
cout <<"The answer is "<< c << endl;

return 0;
}```
Some assistance with this would be appreciated. I'm using Bloodshed's Dev-C++ as a compiler.

2. Originally Posted by Matttan8989
I'm new to coding and I'm trying to make a program that will simply add two numbers together and give an answer.

Code:
```#include <iostream>

using namespace std;

int main ()
{
float a, b, c;
c = a+b;

cin >>a>>b;
cout <<"The answer is "<< c << endl;

return 0;
}```
Some assistance with this would be appreciated. I'm using Bloodshed's Dev-C++ as a compiler.
the problem is how you're initialising the variable c. You're trying to initialise it to equal the sum of a and b, but you only ask for values of a and b after wards. Remember, C++ is a procedural language, and you have to initialise c only after you get the values of and b.

something like this
Code:
```

cin >> a >> b;

float c = a+b;```

3. c = a + b doesn't mean anything until you have a + b. Move that down so that c doesn't contain garbage:

Code:
```    cin >>a>>b;
c = a + b;```
Hope that helps - I'm new too -

dra beat me to it!

4. Oh, all right! Thanks!

5. Hmm, I changed the code to this:

Code:
```#include <iostream>

using namespace std;

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

cin >>a>>b;
c = a+b;
cout <<"The answer is "<< c << endl;

return 0;
}```
I don't understand the problem...

6. Problem? Are you getting a compile error? That code works correctly for me.

7. Can't see the result? You need to add

Code:
```cin.ignore();
cin.get();```
All credit to ILoveVectors.

-JM

8. Ah! Thank you everyone =)

9. lol why do i get credit i didnt even get to respond,
was watching a movie, i think im addicted to these
boards i check them like every 30 minute,
even if im watching a movie.