Whats wrong with my calculator?

it's not printing the answer of the sum towards the end. Instead it says process returned 0 (it doesn't print the sum of the numbers). Please help!

#include <iostream>

using namespace std;

int main()
{
int a;
int b;
int sum;

cout << "Enter a number hoss! \n";
cin >> a;

cout << "Enter another number \n";
cin >> b;

sum = a + b;
cout << "the sum of those numbers is" << sum << endl;
}

p.s it prints out the first 2 couts perfectly fine.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

using namespace std;

int main()
{
int a;
int b;
int sum;

cout << "Enter a number hoss! \n";
cin >> a;

cout << "Enter another number \n";
cin >> b;

sum = a + b;
cout << "the sum of those numbers is" << sum << endl

// the console close too fast you need to add a pause so you can see the result.
int x;
cin >> x;
return 0;
}
Your code is fine, u just need system("pause"); at the end or a return 0; to prevent the window from closing after printing the result.
SeNNa

I would avoid using system("pause"); and return 0; doesn't prevent the window from closing, it just means the program terminated successfully.
You could also include conio.h and use the function getch().
Topic archived. No new replies allowed.