How do I set up an array that can hold up to 50 users

For a HW I have to write a program that simulates a website login. I am already provided with a file that has 10 users already each with their own

userID: a string (no blanks permitted)
password: a string (no blanks permitted)
PIN: an integer (4 digits)

and the file reads it as


1
2
3
4
5
6
7
  struct UserRecord
{
   string userID;
   string password;
   int PIN;

};


the strings for both the user ID and password cannot contain blanks either

so how do I set it up as an array to hold 50 and then read in the number of users and then read the user data into your array of structs and then after it Echoprints all input and Print user data in table format. ? (I really need help here)
Last edited on
I would recommend a vector, but if you have to use an array you would do it similar to this (it is ugly, but getting dinner ready so threw this together fast):
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
#include <iostream>
#include <string>

struct UserRecord
{
	std::string userID;
	std::string password;
	int PIN;
};

int main()
{
	UserRecord array[50];
	
	std::cout << "Enter 50 entries: ";
	for (int j = 0; j < 50; j++)
	{
		std::cin >> array[j].userID;
		std::cin >> array[j].password;
		std::cin >> array[j].PIN;
	}
	
	for (int i = 0; i < 50; i++)
	{
		std::cout << array[i].userID << " : " << array[i].password
		          << " : " << array[i].PIN << std::endl;
	}
	
	return 0;
}


For reading into them you could use getline
Last edited on
Topic archived. No new replies allowed.