Hey all, this probably is a simple fix and i just don't see it.
I am having trouble printing out a code. I am supposed to print a list of User-names passwords and Pin numbers in visual C++ console, but when i run the program my pin numbers seem to be set automatically to a large random number.
here's some of my code:
=================================================
const int MAXUSERS = 100;
// struct type
struct Login
{
string
username,
password;
int PIN;
};
typedef Login Users [MAXUSERS];
void ReadAllUsers (int numusers, Users ID);
void PrintAllUsers (int numusers, const Users ID);
void PrintOneUser (Login inID);
int main ()
{
Users ID;
int numusers;
//read's file to pull into struct
ReadAllUsers (numusers, ID);
//print list of users
PrintAllUsers (numusers, ID);
}
void ReadAllUsers (int numusers, Users ID)
{
int lcv; // for loop counter
int pins = 0;
ifstream infile; // input data file
// open the data file; abort run if can't open
infile.open ( "file.txt" );
if (!infile)
{
infile.clear();
cout << "Error, file could not be opened."
<< endl << endl;
exit (EXIT_FAILURE);
}
infile >> numusers;
infile.ignore (200, '\n');
for (lcv = 0; lcv < numusers; lcv++)
{
getline (infile, ID[lcv].username);
getline (infile, ID[lcv].password);
infile >> ID[lcv].PIN;
infile.ignore (200, '\n');
} // for loop
infile.clear ( );
infile.close ( );
}
=========================================================
I am pulling information for a text file that looks something like this (minus the <<---***** i added that to explain what each item is for):
5 <<-- first input saying how many users
gen34 <<--- username
mixitup <<-- password
8844 <<--- PIN #
marks67
genesis
9494
.....ect.
and repeats a couple more times.
When I debug the program, all my int (lvc, numusers, PIN) are being set to -858993460. I can't seem to figure out why. It should be pulling 5 from the first value, then username and password are being pulled in the struct correctly, then i see PIN set to some ridiculous number.
Thanks.