Let user input # of restaurants, and I cannot read them back out

I have the program asking the user how many restaurants they want to choose from. They then enter how many restaurants they picked. I then want it to read the choices back out, but for some reason my second for loop just keeps looping and won't stop. I cannot figure out why. I also tried using a different integer (int j) for the second loop, and that changed nothing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <string>
#include <cstdlib>


using namespace std;

int main()
{
    int num_places;
    string places[100];


    cout << "How many places do you want to eat at today?";
    cin >> num_places;

    for (int i=1; i <= num_places; ++i)
        {
            cout << "What is your number " << i << " place you want to eat at: ";
            cin >>  places[i];
            cout << endl;
        }

    for (int i=1; i <= num_places; ++i)
    {
        if (i=1)
            cout << "Your choices are: " << places[i];

        cout << "                  " << places[i];

    }

    return 0;
}
Last edited on
1
2
if (i==1)
    cout << "Your choices are: " << places[i];
Ahhhhh thank you! I knew it was something simple. You are a life saver.
Just as a quick note, you will want to change your second loop to something like this.
1
2
3
4
5
6
  
if (i==1)
            cout << "Your choices are: " << places[i];

else
        cout << "                  " << places[i];


Or else it will print out the 1st option twice.
Oh you are right. Thank you very much.
Topic archived. No new replies allowed.