Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7902533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:31:26+00:00 2026-06-03T09:31:26+00:00

Building a simple app here; the methods in question: static coin class public static

  • 0

Building a simple app here; the methods in question:

static coin class

public static void SetUpCoins() {
        coin1 = new Coin(); 
        coin2 = new Coin();
    }

 public static void PlayConsole() {
        SetUpCoins();
        OutputWinner();            
    }


      public static void OutputWinner() {

        if (coin1.ToString() == "Heads" && coin2.ToString() == "Heads") {
            Console.WriteLine("You threw Heads - you win");
            ++point_player;
        } else if (coin1.ToString() == "Tails" && coin2.ToString() == "Tails") {
            Console.WriteLine("You threw Tails - I win");
            ++point_comp;
        } else {
           Console.WriteLine("You threw Odds");
           WaitForKey_ConsoleOnly("Press any key to throw again");
           PlayConsole();
        }

        Console.WriteLine("You have {0} points and the computer has {1} points", point_player, point_comp);

        if (WantToPlayAgain_ConsoleOnly()) { // ask user if they want to play again; return bool
            PlayConsole();
        }
      }

 private static bool WantToPlayAgain_ConsoleOnly() {
            string input;
            bool validInput = false;
            do {
                Console.Write("Play Again? (Y or N): ");
                input = Console.ReadLine().ToUpper();
                validInput = input == "Y" || input == "N";
            } while (!validInput);

            return input == ("Y"); 
        }

If false was to return from WantToPlayAgain_ConsoleOnly() the program does not exit. Here is an example of the output, which explains my problem:

enter image description here

Why, when WantToPlayAgain_ConsoleOnly is false, does the program not pass control the playConsole method then exit. instead of this repetition.

After OutputWinner is finished running, it then jumps into PlayConsole, and then back into the else statement of the OutputWinner – not sure why.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:31:27+00:00Added an answer on June 3, 2026 at 9:31 am

    As the previous answers said, you have a problem when you throw odds.
    Because at that point you call the exact same method again and when that call returns, you resume right at the score display and the player is asked again to play.
    Because you are calling PlayConsole recursively, that means for every time you throw “Odd”, you will get one more prompt that you didn’t ask for.

    You could restructure the method like this:

      public static void OutputWinner() {
        do {
            // Game code
        }
        while (WantToPlayAgain_ConsoleOnly());
      }
    

    That also gets rid of the recursion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the concept for this relatively simple Flash app I'm building: Check an XML
I'm working with ASP.NET MVC 2 and building a simple business app. Here are
Am new to Android, and am building a simple calculator app. I want to
I'm soon going to be starting some iPhone Development (3.0) building a simple app
I am building a very simple app to store data on people like name,
I am building a simple Django app that will use scribd to display documents.
I'm building a simple accounting app to be used for personal finance. A user
I'm looking at building a simple web app that will expose an API that
I've been tasked with building a very simple app that that has a series
I am currently in the planning stages of building a simple Django web app

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.