I don't understand what's going on... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I don't understand what's going on...

"#include <iostream> using namespace std; int main() { int a, b; int sum; cout << "Enter a number \n"; cin >> a; cout << "Enter another number \n"; cin >> b; sum = a + b; cout << "Sum is: " << sum << endl; return 0; } " Asks me to input my numbers at the same time. So I input 1 and 2, expecting 3 as a result. instead it returns: "Enter a number Enter another number 1 2" I haven't changed the tutorial code, I simply ran what was there. I'm not sure how to proceed.

16th Jul 2016, 3:57 AM
David
David - avatar
5 Answers
+ 1
Ah! I figured it out. So, I looked into the example, and if says something like "enter an number" then "enter another" it appears that for that code, it never has an operator to add. all it does is output the two with a space inside. Such as (this is not the whole code, as I don't feel like typing in 'include iostream' and such. cout a << " " << b << endl; The function (example) was not meant to add, it was just meant to show you can have as many inputs as you please. I have to admit it was so weird to realize this. I was about to go insane because the code looked like if should work...
16th Jul 2016, 5:48 AM
Autumn S
Autumn S - avatar
0
What have you inputted? Make sure you don't put any spaces before or after the 1 & 2, only between. Let me know it this is helpful, or if you still have trouble.
16th Jul 2016, 5:25 AM
Autumn S
Autumn S - avatar
0
I only input "1 2". Nothing else at all.
16th Jul 2016, 5:31 AM
David
David - avatar
0
That seems very peculiar. Have you tried playing around with it a bit? I will have to get back to you on this question, and hopefully have an answer (as this code appears as if it should work...)
16th Jul 2016, 5:35 AM
Autumn S
Autumn S - avatar
0
Yea, after my initial post, I completed a few more lessons. I have this habit of getting ahead of myself when trying to learn to program. Instead of learning it first, I learn some and then mess around with it and break things. Thanks for the help though!
16th Jul 2016, 7:00 AM
David
David - avatar