This is part of a group project. It\'s a \"lottery program\" where up to 200 con
ID: 3835490 • Letter: T
Question
This is part of a group project. It's a "lottery program" where up to 200 contestants are allowed to play. As you can see on my program, if the numbers they insert match with the winning numbers, they'll win different prizes (depending on how many numbers they matched). I have to create a separate text file that includes the name of the contestant, what numbers they picked and their prize (if any). My problem is, when I create the separate text file, it displays Player 1, Player 2.. but I would like to have the name the user and the numbers they picked (I just have the numbers of matches but not what actual numbers they plugged in). Moreover, because is part of a project I should make it a user defined function, I'm a little confused on how to do it. My part only requires me to create the separate text file with the information, so how can I make my part work independently of the other people's code (but I want to make the user defined function with the code I've already written).Thank you so much for your help :( Moreover, because is part of a project I should make it a user defined function, I'm a little confused on how to do it. My part only requires me to create the separate text file with the information, so how can I make my part work independently of the other people's code (but I want to make the user defined function with the code I've already written).
Thank you so much for your help :(
I'm attaching a picture of my code and the text file.
Part VII include siostrean? include fstream> #include
Explanation / Answer
Here is user defined method for writting player information in a file.
Please note if you want to store all player info at once, you need to store names of player in an array as well (thus you have to ask player names from players). This all depends a little on what and how your other team members plan are to develop other parts and delegate writting responsibility to your function.
// players string array for name, numbers contain number choosen by user, n is number of players
void writeDataToFile(string players[], int numbers[][5], int n)
{
ofstream out("playerdata.txt");
out << n << endl;
for(int i = 0; i < n; i++)
{
out << players[i] << endl;
for(int j = 0; j < n; j++)
{
out << numbers[i] << " ";
}
out << endl;
}
out.close();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.