1

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.

4
  • 1
    first things first: edit your code so we get a working example. the part you show so far does not even compile when looked at. once this is established we can discuss scope, for example of guessedProducts which should certainly be declared before the program enters the game loop. Commented Jun 3, 2018 at 23:20
  • 1
    This isn't even close to compiling. Your missing braces, you have a switch inside of a case that isn't inside of a switch... Honestly, at least try Commented Jun 3, 2018 at 23:25
  • 1
    +1 because I'm tired of the stupid downvote police scaring away new users. There was a really great blog post on meta about exactly this sort of thing recently. Commented Jun 4, 2018 at 0:58
  • game.Start() gives you next Question ? and where are you adding things in game.PreviousGuesses ? Commented Jun 4, 2018 at 3:06

1 Answer 1

2

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
   }
Sign up to request clarification or add additional context in comments.

2 Comments

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?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.