looping

my teacher told me my "name-in" string should loop from first name-in to las name-in i just need to ask how to make sure that the number of students names matches the number of students i originally entered.

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
35
  #include <iostream>
#include <string>
using namespace std;

int main()
{
   int students;
   string name-in;
   int first;
   int last;
    cout << "Please enter the number of students in your class" << endl;
    cin >> students;
        if((students>=1) && (students<=25)){
        cout << "please enter the names of your students." << endl;
        cin >> name-in;
        first = name-in;
        last = name-in;
        
        while(students<=2)
        if (name-in < first)
              first = name-in;
        if (name-in > last) 
                last = name-in       
                  
        
         student++
                         }
        
        else{
             cout << "please press any key and enter a new number." << endl;
             }
      system("pause");              
      return 0;  
    }
closed account (28poGNh0)
I dont know what are you trying to do but I think that will help you

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
35
36
37
# include <iostream>
# include <vector>
# include <string>
# include <cstdlib>
using namespace std;

int main()
{
    int students;

    cout << "Please enter the number of students in your class" << endl;
    cin >> students;
    vector<string> name_in;
    string name = "default";

    if((students>=1) && (students<=25))
    {
        cin.ignore();

        int i=1;
        while(name.size()!=0)
        {
            cout << "Enter the name of the student nbr " << i++ << " -> ";
            getline(cin,name);
            if(name.size()!=0)
                name_in.push_back(name);
        }
    }else cout << "please press any key and enter a new number." << endl;

    if(name_in.size()==(size_t)students)
        cout << "The number is even" << endl;
    else cout << "It is not!" << endl;

    system("pause");

    return 0;
}
this is great thank you but the only thing i'm missing is trying to limit students to the original number entered in the program. i tried setting i=students.
Topic archived. No new replies allowed.