Carolyn

Carolyn

  • NA
  • 15
  • 2.9k

New User Needs Help with Console Application

Jun 12 2013 8:41 PM
I'm a front end developer who wanted to learn C#.  I'm taking this class and we were presented with a project and I'm having a major disconnect and I am hoping that some kind soul will help me out.  This is very basic and I am so frustrated that I don't understand how to set this up.  I need to create a console application where you can make a bet, then play coin toss or roulette.  I figured I should make each piece seperate and then put them together.  I made the Coin Toss first and then the menu and now I don't know how to call the coin toss app from the menu!!!  Please help me.

I actually was on the right track with coin toss:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PlayCoinToss
{
    class Program
    {
        static void Main(string[] args)
        {
            string user;
            int user1; // User 1 is the input--what I'm selecting 
            Random numberGenerator = new Random();
            bool playAgain = true;
            string userChoice;
            string houseChoice;
            int house;
            string outcome;
            //Below I'm changing what the console looks like:

            // set background to white
            Console.BackgroundColor = ConsoleColor.White;
            // set foreground to blue
            Console.ForegroundColor = ConsoleColor.Red;
            // clear the screen
            Console.Clear();
            //greeting players
            Console.WriteLine("The user is betting against the house");
            
            while (playAgain == true)
            {
                Console.Write("Please Make Your Selection (1 = Heads and 2 = Tails): ");
                user = Console.ReadLine();
                house = numberGenerator.Next(1, 3);

                while (!int.TryParse(user, out user1) || user1 <= 0 || user1 >= 3) //this is the houses selection.  I'm going to be betting against the house
                {
                    Console.Write("Please Make Your Selection (1 = Heads and 2 = Tails): ");
                    user = Console.ReadLine();
                }
                //below are the rules for me the player
                if (user1 == 1)
                {
                    userChoice = "Heads";
                }

                else
                {
                    userChoice = "Tails";
                }
                //below are the rules for me the house --or whatever I'm playing against
                if (house == 1)
                {
                    houseChoice = "Heads";
                }

                else
                {
                    houseChoice = "Tails";
                }
                //Below I have to figure out who wins and who loses instances of this game
                if (house == user1)
                {
                    outcome = "lose"; //if there is a tie then no money is won or lost
                }
               //need to put how I lose here
                else
                {
                    outcome = "win";
                }

                //Below I have to figure out how to print results and if they want to play again
                Console.Write("You chose " );
                Console.Write(userChoice);

                Console.Write(", the house chose ");
                Console.Write(houseChoice);

                Console.Write("You ");
                Console.Write(outcome);

                Console.WriteLine("Do you want to play again? (yes/exit)");
                user = Console.ReadLine();

                while (user != "YES" && user != "yes" && user != "EXIT" && user != "exit") //They can input all caps or all lowercase since I wrote it this way 
                {
                    Console.WriteLine("Error Please enter yes or exit");
                    user = Console.ReadLine();
                }
                if (user == "YES" || user == "yes")
                {
                    playAgain = true;
                }
                else
                {
                    playAgain = false; //the only important thing is that they enter yes
                }


            }
        }
    }
}

I kind of started getting confused reading the requirements after that.  Then I repurposed a menu here
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
 class Program
 {
 static void Main(string[] args)
    {
       
        const int maxMenuItems = 4
            ;

           int selector = 0;
           bool good = false;

            while (selector != maxMenuItems)
           {
              Console.Clear(); 
               DrawTitle();
               DrawMenu(maxMenuItems);
               good = int.TryParse(Console.ReadLine(), out selector);
                if (good)
              {
                   switch (selector)
                   {
                        case 1:
                            Console.WriteLine("// code for case 1 here");
                           break;
                        case 2:
                            Console.WriteLine("// code for case 2 here");
                          break;
                        case 3:
                         Console.WriteLine("// code for case 3 here");
                          break;
                        case 4:
                         Console.WriteLine("Exit");
                         break;
                    
                      default:
                         if (selector != maxMenuItems)
                            {
                                ErrorMessage();
                            }
                            break;
                   }
               }
                else
                {
                   ErrorMessage();
              }
               Console.ReadKey();
            }
        }

       private static void ErrorMessage()
        {
            Console.WriteLine("Typing error, press key to continue.");
       }

        private static void DrawStarLine()
       {
           Console.WriteLine("************************");
        }

        private static void DrawTitle()
       {
            DrawStarLine();
            Console.WriteLine("+++   Lets Play a Game   +++");
            DrawStarLine();
        }

       private static void DrawMenu(int maxitems)
       {
            DrawStarLine();
            Console.WriteLine(" 1. Add Funds");
            Console.WriteLine(" 2. Coin toss");
            Console.WriteLine(" 3. Roulette");
            Console.WriteLine(" 4. Exit program");
            DrawStarLine();
            Console.WriteLine("Make your choice: type 1, 2, 3, 4", maxitems);
            DrawStarLine();
        }
 }
}
  

and now I have managed to totally confuse myself and I'm lost.  Please please help

Answers (12)