0

Hey there im doing a simple two up dos program for an assignment and im having some issues, we have been given a skeleton with methods and forms within it and im pretty sure were not allowed to change it. heres my code:

class TwoUp {
        Coin coin1 = new Coin();
        Coin coin2 = new Coin();
       
        
        void Play_TwoUp() {
            const int HEADS = 0;
            const int TAILS = 2;
            //const int ODDS = 1;
            int coin_one = coin1.Flip();
            int coin_two = coin2.Flip();
            int score = coin_one + coin_two;
            int player_score = 0;
            int house_score = 0;

            switch (score) {
                case HEADS:
                    Console.WriteLine("You threw Heads - You've won!");
                    player_score++;
                    break;

                case TAILS:
                    Console.WriteLine("You thre Tails - You loose.");
                    house_score++;
                    break;

                default:
                    Console.WriteLine("You threw Odds - Throw again.");
                    //Replay();
                    break;
            }
        }

        void Replay() {
            Play_TwoUp();
        }


        public TwoUp() {

        }



        public void Play(int menuOption) {
            Play_TwoUp();


        }


    } //end class TwoUp
}

My problem is that the int coin_one = coin1.Flip(); and coin2.Flip()
come up as cannot convert void to int, however i do have another game which required me to do the same and it has worked by doing it the same way. both are void methods.

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by ShinyDean
0

You don't show the Coin class so it's hard to tell what you need to do.

On the other hand, no where do you have code where you call a void method and store the result in an int. No where. Let me make it clear: No where. void means nothing is returned.

0

As Momerath says, void is void. It is not a value that can ever be returned, unless we confusing it with C/C++ (void *) which can be mapped onto any other pointer type.

0

I fixed the problem ages ago, I was in a rush so wasnt thinking properly haha wasnt ment to use the coin classes Flip, was ment to use another method to return a bool.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.