+ 1
Error
I want make a calculator. Help. #include <iostream> using namespace std; int main() { int a; int b; int sum = a + b; cout << "Number"; cin << a; cout << "Another number"; cin << b; cout << sum }
3 Answers
+ 6
#include <iostream>
using namespace std;
int main()
{
// Always initialize numbers, otherwise you may
// end up having "garbage" value in a & b here.
int a=0;
int b=0;
// You haven't got user input yet, so calculating
// sum here is not the right thing to do
//int sum = a + b;
cout << "Number";
cin >> a; // Use >> operator for accepting input
cout << "Another number";
cin >> b; // Use >> operator for accepting input
// Now you have got the two numbers to add for,
// you can go ahead do the math.
int sum = a + b;
cout << sum; // You forget semicolon ; at the end
}
Hth, cmiiw
+ 5
calculate your sum after getting values from user.
check please!
I want make a calculator. Help.
#include <iostream>
using namespace std;
int main()
{
int a;
int b;
cout << "Number";
cin << a;
cout << "Another number";
cin << b;
int sum = a + b;
cout << sum
return 0;
}
+ 1
Thanks