A) Are there any bad habits that I'm forming that aren't good practices for the professional world of programming?
B) Is there something that I did the hard way that could have been done much simpler?
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace War4{ class Program { static void Main(string[] args) { string playerName; double cash = 250; double betAmount = 0; int player, dealer; char more = 'y'; int win = 0; Console.Write("Enter your name: "); playerName = Console.ReadLine(); do { do { Console.WriteLine("You have {0:C} to bet with", cash); betAmount = GetBetAmount(betAmount); } while (betAmount > cash); Console.WriteLine("{0} press enter to draw a card", playerName); Console.ReadLine(); player = GetCard(); DisplayCard(player); Console.WriteLine("Press enter to see the dealers card"); Console.ReadLine(); dealer = GetCard(); DisplayCard(dealer); win = Evaluate(player, dealer); if (win == 3) { do { Console.WriteLine("TIE!! NOW WE GO TO WAR!!"); Console.WriteLine("{0} press enter to draw a card", playerName); Console.ReadLine(); player = GetCard(); DisplayCard(player); Console.WriteLine("Press enter to see the dealers card"); Console.ReadLine(); dealer = GetCard(); DisplayCard(dealer); win = Evaluate(player, dealer); } while (win == 3); } if (win == 1) { Console.WriteLine("YOU WIN!!"); cash = cash + (betAmount * 2); Console.WriteLine(); } else { Console.WriteLine("YOU LOSE!!"); cash -= betAmount; Console.WriteLine(); } Console.Write("Press [Y] to continue to play: "); more = Convert.ToChar(Console.ReadLine()); Console.WriteLine(); if (cash == 0) { Console.WriteLine("{0} have no more money",playerName); more = 'n'; Console.WriteLine(); } } while (more == 'y' || more == 'Y'); Console.WriteLine("Thank you for playing."); Console.WriteLine(); } static double GetBetAmount(double betAmount) { Console.Write("Please enter bet amount: "); betAmount = Convert.ToDouble(Console.ReadLine()); return betAmount; } static int GetCard() { Random rnd = new Random(); int card = rnd.Next(2, 14); return card; } static void DisplayCard(int card) { if (card == 14) { Console.WriteLine("ACE"); Console.WriteLine(); } else if (card == 13) { Console.WriteLine("KING"); Console.WriteLine(); } else if (card == 12) { Console.WriteLine("QUEEN"); Console.WriteLine(); } else if (card == 11) { Console.WriteLine("JACK"); Console.WriteLine(); } else if (card >= 2 && card <= 10) { Console.WriteLine(card); Console.WriteLine(); } else { Console.WriteLine("Error {0} is invaid card!", card); Console.WriteLine(); } } static int Evaluate(int player, int dealer) { if (player > dealer) { return 1; } else if (player < dealer) { return 2; } else { return 3; } } }}
Your advice is greatly appreciated.