how do you add two numbers in c++

7 posts

Flag Post

is it something like this

#include
int main()
{
int a,b,c;
a=10;
b=10;
c=a+b;
return 0;
}

 
Flag Post

wtf

 
Flag Post

We aren’t here to do your homework.

 
Flag Post

Kinda, more or less.
To start with, you don’t need the #include statement unless you’re using something that requires a library (ex: a cout requires iostream).
Which then brings your program to something similar to what you have:

int main(){
int a,b,c;
a=10;
b=10;
c=a+b;
return 0;
}

But, like most people are wondering, why are you asking a simple C++ question here instead of:

  • Looking it up
  • Trying it yourself. Assuming you’re following a book or class, the first thing you learn is how to print stuff out. Write some code, run it, and output the result of c. If it doesn’t work, find out why and fix it. After all, writing the program isn’t even half the battle. Issues will come up, and you’ll need to become good at finding them.
 
Flag Post
Originally posted by Drakim:

We aren’t here to do your homework.

im just asking bro its no a h.w

 
Flag Post

You do it like you would do in almost any algebraic based language.

 
Flag Post

Try doing 1 + 2…