Reputation: 23
i'm creating a simple console application. The basic idea is to let user enter an amount of players, then a loop will start to ask for players' name for x time according the amount the user entered. Then the game part will start, a loop will loop through the player list, each player is going to throw a ball 3 times and each time the user will enter a score number; these scores will be added and shown when that user finished his throw. Loop goes to the next player and repeat another 3 throw. While the total score is less than 100, the loop will restart from the first player, and letting the first player to throw 3 times again, at the end of the throw, his score will be the score from the first round plus the second round.
Right now i'm not sure how to create such a list and loop to separate the scores between players. i have two lists, one for storing players and one for storing scores, the scores from different players are stored in one same list, and so i can't calculate the sum of each individual player correctly. Any idea and tips would be very helpful!
Upvotes: 0
Views: 524
Reputation: 208
A way to do it without adding Class is by using a Dictonary>. Key = player name and Value = list of score for that player.
Start by adding each player in the Dictonary with a empty List.
then in your loop you can have something like :
int total = 0;
if(playerDictionary.ContainsKey(playerName))
foreach(int score in playerDictionary[playerName])
total += score;
Console.WriteLine(total)
Upvotes: 0