c++ - why does it wrap without endl;? -
i'm c++ beginner , wrote simple program:
#include <iostream> using namespace std; int readnumber() { cout << "insert number: "; int x; cin >> x; return x; } void writeanswer(int x) { cout << "the sum is: " << x << endl; } int main() { int x = readnumber(); int y = readnumber(); int z = x + y; writeanswer(z); return 0; }
i don't understand why output this:
insert number: 3 insert number: 4 sum is: 7
and not like:
insert number: 3insert number: 4the sum is: 7
since in readnumber
function there no endl;
.
what missing?
(of course i'm happy result get, it's unexpected me)
that's because push enter after enter numbers (-:
first 2 lines of "output" aren't pure output. it's mixed input.
Comments
Post a Comment