I wrote this code to open a file and store everything into a global char array team [800]
void readfile(char usrinput[]) // opens text file
{
char temp;
ifstream myfile (usrinput);
int il = 0;
if (myfile.is_open())
{
while (!myfile.eof())
{
temp = myfile.get();
if (myfile.eof())
{
break;
}
team[il] = temp;
il++;
}
myfile.close
}
else
{
cout << "Unable to open file. (Either the file does not exist or is formmated incorrectly)" << endl;
exit (EXIT_FAILURE);
}
cout << endl;
}
The user is required to create a input file that is formatted where the first column is a name, second column is a double, and third column is also a double. Something like this:
Trojans, 0.60, 0.10
Bruins, 0.20, 0.30
Bears, 0.10, 0.10
Trees, 0.10, 0.10
Ducks, 0.10, 0.10
Beavers, 0.30, 0.10
Huskies, 0.20, 0.40
Cougars, 0.10, 0.90
I want to add a check currently, where if the user only enters 7 teams, it with exit out of the program, or if the user enters more than 8 teams, or double numbers.
Ive tried creating an if statement using a counter (counter != 8 and you break out of the loop/program) in another function where I split this into three different arrays but that did not work. I am now trying to accomplish this check within this function and if its possible could someone guide me in the right direction? I appreciate all the help, and please let me know if i can provide more information to make things less vague.
EDIT: we are not allowed to use vectors or strings