I dont know what you read to do these things because :
- nobody does this:
cout << endl << " Number " << i;
. You should learn using it like this: cout << " Number " << i<<endl;
and if you specifically want a newline at the first, you can just putcout<<endl;
or cout<<"\n";
- As of my understanding of your question, i think you're missing the point here. You have a space between the
" Number "
, which you should probably change to "Number "
- You specifically and explicitly took input and printed the input of 'potato' at the end.
This part :
string name;
cin >> name;
cout << endl << endl << name;
is after this part:
for (int i = 0; i <= 10; ++i) {
cout << endl << " Number " << i;
}
which is obvious that the text 'potato' that you entered is printed after 10.
This code might help you:
#include <iostream>
using namespace std;
int main()
{
string name;
for (int i = 0; i <= 10; ++i)
{
cout << "Number: " << i << endl;
}
cin >> name;
cout << name;
return 0;
}
this code shows this output:
1
2
3
4
5
6
7
8
9
10
Potato
I hope this helps!!!