+ 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.
5 Réponses
+ 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...
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.
0
I only input "1 2". Nothing else at all.
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...)
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!