+ 2

Can anyone help me? I want to put two numbers in and have their sum be the output

https://code.sololearn.com/c2IzIlJgk09n/?ref=app

2nd Jul 2017, 5:14 PM
Ethan Perdue
Ethan Perdue - avatar
7 Respostas
+ 8
Just change the order, you can't calculate the sum without knowing the values of x and b :) So first take input, then calculate y. https://code.sololearn.com/cR9C779b4vlx/?ref=app
2nd Jul 2017, 5:22 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 3
int x,b,y; cout<<"enter two numbers"; cin>>x>>b; y=x+b; cout<<y;
2nd Jul 2017, 5:24 PM
Mayur Chaudhari
Mayur Chaudhari - avatar
+ 3
Thank you for all your answers! I know the question was basic but I'm just starting at this.
2nd Jul 2017, 6:14 PM
Ethan Perdue
Ethan Perdue - avatar
+ 2
This code can be helpful to you https://code.sololearn.com/c0QqMzlIJVqD/?ref=app
2nd Jul 2017, 5:18 PM
Ledio Deda
Ledio Deda - avatar
+ 2
I think that the problem with your code is this: You should put cin before you declare the variable "y" for the sum...
2nd Jul 2017, 5:21 PM
Ledio Deda
Ledio Deda - avatar
+ 2
int main() { int x, y, z; std::cout << "Enter two integers: "; std::cin >> x >> y; z = x + y; std::cout << "The sum of " << x; std::cout << " & " << y << " is "; std::cout << z << std::endl; return 0; }
2nd Jul 2017, 5:50 PM
Jacob
Jacob - avatar
0
Don't you worry... I've had the same problem when I started programming😉✌✌
2nd Jul 2017, 6:38 PM
Ledio Deda
Ledio Deda - avatar