+ 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 }

18th Dec 2017, 9:30 AM
Иван Сахно
Иван Сахно - avatar
3 odpowiedzi
+ 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
18th Dec 2017, 10:10 AM
Ipang
+ 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; }
18th Dec 2017, 9:57 AM
Zohaib 👑
Zohaib 👑 - avatar
+ 1
Thanks
18th Dec 2017, 11:23 AM
Иван Сахно
Иван Сахно - avatar