I have game app that has 5 items with description and price. after I display description user guess the price and this item goes to to previous guesses list. When I am looping through my game and user finishes it, I want the console to ask user again if he want to play. In that case i don't want to show the item twice, meaning i need to make sure that I never show the product twice.
1 Answer
From what i can tell, you need to simply skip the loop with an if statement. You need to declare and initialize a bool before your game loop and update it if the player chooses to retry
bool retry = false
...
if(!retry)
foreach (var p in guessedProducts)
{
Console.Write(p.ToString() + "\r\n");
}
...
if(choice == 1)
{
retry = true
}
2 Comments
Den
I added retry = true as well as this: retry = true; Console.Write("Gueess the price of the product: "); nextProduct = game.Start().Description; Console.WriteLine("Description: " + nextProduct); I get it working except that incrementing my guesses should only apply per item, and its incrementing all of them together, Do you know by any chance how to fix that?
Sulai
Sorry for late reply.Sadly i cannot see the original code anymore but if you simply add an array or list with separate int's to increment it should solve the problem.
guessedProductswhich should certainly be declared before the program enters the game loop.switchinside of acasethat isn't inside of aswitch... Honestly, at least trygame.Start()gives you next Question ? and where are you adding things ingame.PreviousGuesses?