For Loops

Jun 12, 2014 at 9:57pm
I began learning C++ today, and it's my first programming language so please bear with me. I want to execute a for loop that would allow me to receive the input as a string and then output it, multiple times.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

using namespace std;

int main()
{
    string input = "";
        cout << "What is your name: \n";
        for ( int x = 10; x < 20; x++ )
        getline( cin, input );
        cout << "Your name is " << input <<"!";
    cin.get();
}


So it would ask you the question, output the answer, and repeat.
If you guys could help me, I'd be very appreciative.

Thank you.
Jun 12, 2014 at 10:06pm
Jun 12, 2014 at 10:08pm
There code above is heading in the right direction. But the main problem is the missing braces { and } around the statements which are to be controlled by the loop.

Take a look at some of the examples in the tutorial;
http://www.cplusplus.com/doc/tutorial/control/
Jun 12, 2014 at 10:14pm
Thanks guys.
Topic archived. No new replies allowed.