static void Main(string[] args) { string answer; string UserAnswer; double price; double total = 0; List <double> UserOrder = new List <double>(); Console.WriteLine(GetMenu()); do { Console.WriteLine(" "); Console.WriteLine("What would you like to order from the menu?>>"); answer = Console.ReadLine(); price = CalculatePrice(answer); UserOrder.Add(price); ShowReceipt(price); Console.WriteLine("Would you like to order anything else?>>"); UserAnswer = Console.ReadLine(); } while (UserAnswer.ToLower() == "yes"); foreach (double item in UserOrder) { total += price; } Console.WriteLine($"Your total for everything is: {total.ToString("C2")}"); }
static void Main(string[] args) { /* Create a new Console Application, name the solution Homework 6 and the project CoffeeShop. * You are the owner of a small coffee shop. In order to get more people to your website, you want to create a * “Coffee House Game” that website visitors can play. * * - DONE The game will call the GetMenu method to display the menu, and then ask the user what they want to order. * - Then, the application should call the Calculate Price method and the Display Receipt method. * when the receipt for that item has been displayed, * - the application should ask the user if they would like to order anything else. * - Once they say no, the application should output the total of everything the user has ordered. * - The application should also thank the user for playing before closing. */ string answer; string UserAnswer; double total = 0; List <string> CustomerOrder = new List <string>(); string output = GetMenu(); Console.WriteLine(output); do { Console.WriteLine("What would you like to order from the menu?>>"); answer = Console.ReadLine(); CustomerOrder.Add(answer); double price = CalculatePrice(answer); Console.WriteLine($"Price: ${Convert.ToDouble(price)}"); total += price; ShowReceipt(price); Console.WriteLine("Would you like to order something else?>>"); UserAnswer = Console.ReadLine(); } while (UserAnswer.ToLower() == "yes"); //going through the list to show what they ordered Console.WriteLine("You ordered: "); bool isFirstTime = true; foreach (string item in CustomerOrder) { if (isFirstTime) { Console.Write(item); isFirstTime = false; } else { Console.Write(", " + item); } } Console.WriteLine(); Console.WriteLine("Your total comes out to be " + total.ToString("C2")); Console.WriteLine(" "); Console.WriteLine("Thank you for playing!"); }
static void Morse_code() { //Create string variable for 'sos' string UserAnswer; char[] CharArray; //Use string array for Morse code string[,] Dictionary_arr = new string[, ] { { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }, { ".- ", "-... ", "-.-. ", "-.. ", ". ", "..-. ", "--. ", ".... ", ".. ", ".--- ", "-.- ", ".-.. ", "-- ", "-. ", "--- ", ".--. ", "--.- ", ".-. ", "... ", "- ", "..- ", "...- ", ".-- ", "-..- ", "-.-- ", "--.. ", "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----." } }; while (true) { UserAnswer = ConsoleFunc.AskUser("Please, enter text for morse"); if (UserAnswer.Length == 0) { continue; } UserAnswer = UserAnswer.ToLower(); foreach (var item in UserAnswer) { for (int i = 0; i < Dictionary_arr.GetUpperBound(1); i++) { if (item.ToString() == Dictionary_arr[0, i]) { //Use ToCharArray() method for string to copy charecters to Unicode character array CharArray = Dictionary_arr[1, i].ToCharArray(); //Use foreach loop for character array in which foreach (var item2 in CharArray) { switch (item2) { case '.': //Implement Console.Beep(1000, 250) for '.' Console.Beep(1000, 250); break; case '-': // and Console.Beep(1000, 750) for '-' Console.Beep(1000, 750); break; default: //Use Thread.Sleep(50) to separate sounds Thread.Sleep(50); break; } } } } } break; } }
public override void Run() { const int minVal = 1; const int maxVal = 100; Console.Clear(); ShowTheCondition(); var rand = new Random(); int num = rand.Next(minVal, rand.Next(minVal + 1, maxVal)); // lets try random max value for more random number :) string UserAnswer; int parseResult; int counter = 0; while (true) { UserAnswer = AskUser("Please, enter your guess (0 to repeat the rules):"); if (UserAnswer.ToLower() == "q") { return; } int.TryParse(UserAnswer, out parseResult); if (parseResult == 0) { ShowTheCondition(); continue; } else if (parseResult > maxVal || parseResult < minVal) { ShowError("You must enter number between " + minVal + " and " + maxVal); continue; } counter++; if (parseResult > num) { SendMessage(parseResult + " - Too high!", ConsoleColor.Magenta); } else if (parseResult < num) { SendMessage(parseResult + " - Too low!", ConsoleColor.Blue); } else { SendMessage(parseResult + " is right! Conngratilations, you try only " + counter + " times!", ConsoleColor.Cyan); Console.ReadLine(); return; } } }
static void CheckAnswer(string mode) { string UserAnswer; do { UserText("- "); UserAnswer = Console.ReadLine(); if (UserAnswer.ToLower() != "нет" && UserAnswer.ToLower() != "да") { OldManText("- Ты в бреду, странник?.. Выпей воды и попробуй еще раз...\r\n"); } }while (UserAnswer.ToLower() != "нет" && UserAnswer.ToLower() != "да"); if (mode == "door") { if (UserAnswer.ToLower() == "нет") { DoorIsOpen = false; } else { DoorIsOpen = true; } } else if (mode == "arms") { if (UserAnswer.ToLower() == "нет") { UserHaveArms = false; } else { UserHaveArms = true; } } else { if (UserAnswer.ToLower() == "нет") { UserHaveKey = false; } else { UserHaveKey = true; } } }
static void Main(string[] args) { //a list to hold all of the order information List <string> Order = new List <string>(); string answer; string UserAnswer; double total = 0; Console.WriteLine(GetMenu()); Console.WriteLine(" "); do { //get their order and add it to the list Console.WriteLine("What would you like to order from the menu?"); answer = Console.ReadLine(); Order.Add(answer); double price = CalculatePrice(answer); CalculatePrice(answer); ShowReceipt(price); total += price; Console.WriteLine("Would you like to order something else from the menu?"); UserAnswer = Console.ReadLine(); } while (UserAnswer.ToLower() == "yes"); Console.WriteLine("You ordered: "); bool isFirstTime = true; foreach (string item in Order) { if (isFirstTime) { Console.Write(item); isFirstTime = false; } else { Console.Write(", " + item); } } Console.WriteLine($" Total of all Ordered: {total.ToString("C2")}"); Console.WriteLine("Thank you for playing!"); }
static void Main(string[] args) { List <ToyBox> toyboxes = new List <ToyBox>(); string UserAnswer; Console.WriteLine("Please add a toybox."); do { ToyBox newToyBox = GetNewToyBoxFromUser(); toyboxes.Add(newToyBox); Console.WriteLine("Do you want to add another toybox? yes or no>>"); UserAnswer = Console.ReadLine(); } while (UserAnswer.ToLower() == "yes"); string answer; foreach (ToyBox toyBox in toyboxes) { Console.WriteLine($"Time to fill {toyBox.Owner}'s Toy Box!"); do { Toy newToy = GetNewToyFromUser(); toyBox.Toys.Add(newToy); Console.WriteLine("do you want to enter another toy? yes or no?>>"); answer = Console.ReadLine(); } while (answer.ToLower() == "yes"); } Console.WriteLine("Time to take a look at all your toys!"); Console.WriteLine(); foreach (ToyBox toyBox in toyboxes) { Console.WriteLine($"Content of {toyBox.Owner}'s ToyBox!"); foreach (Toy toy in toyBox.Toys) { Console.WriteLine(toy); } } foreach (ToyBox TB in toyboxes) { Console.WriteLine($"{TB.GetRandomToy().Name}"); } }
public override void Run() { Console.Clear(); ShowTheCondition(); string UserAnswer; int parseResult; long result; int i; List <long> calculations = new List <long>(); calculations.Add(1); // for 0 while (true) { UserAnswer = AskUser("Please, type number (r to repeat the rules)"); if (UserAnswer.ToLower() == "q") { return; } else if (UserAnswer.ToLower() == "r") { ShowTheCondition(); continue; } int.TryParse(UserAnswer, out parseResult); if (calculations.Count() - 1 >= parseResult) { ShowResult(parseResult + "! = " + calculations[parseResult]); continue; } result = calculations.Last(); i = calculations.Count(); for (; i <= parseResult; i++) { result *= i; calculations.Add(result); } ShowResult(parseResult + "! = " + result); } }
public void Check() { if (string.IsNullOrEmpty(UserAnswer)) { Mode = IndicationMode.Normal; } else if (UserAnswer.ToLower() == Ru.ToLower()) { Mode = IndicationMode.Correct; } else { Mode = IndicationMode.Error; } var a = PropertyChanged; if (a != null) { a(this, new PropertyChangedEventArgs("Mode")); } }
public override void Run() { const int UserNumbersCount = 2; Console.Clear(); ShowTheCondition(); string UserAnswer; string[] UserAnswerArr; double?[] UserNumbers; CalculatorVariant SelectedVariant; while (true) { UserAnswer = AskUser("Please, type numbers by step (0 to repeat the rules)"); if (UserAnswer.ToLower() == "q") { return; } else if (!Enum.TryParse(UserAnswer, out SelectedVariant) || !Enum.IsDefined(typeof(CalculatorVariant), SelectedVariant)) { continue; } if (SelectedVariant == CalculatorVariant.Repeat) { ShowTheCondition(); continue; } UserNumbers = new double?[UserNumbersCount + 1] { null, null, null }; // +1 for result int j = 0; while (true) { UserAnswer = AskUser(j == 0 ? "Please, enter 1 or 2 numbers" : "Please, enter 1 more number"); UserAnswerArr = UserAnswer.Split(); if (UserAnswerArr.Count() == 0) { continue; } for (int i = 0; i <= Math.Min(UserNumbersCount, UserAnswerArr.Count() - 1); i++) { double parseResult; Double.TryParse(UserAnswerArr[i], out parseResult); for (j = 0; j <= UserNumbersCount - 1; j++) { if (UserNumbers[j] == null) { UserNumbers[j] = parseResult; break; } } if (j == UserNumbersCount - 1) { break; } } if (j != UserNumbersCount - 1) { continue; } else if (SelectedVariant == CalculatorVariant.Divide && UserNumbers[1] == 0) { ShowError("You can't Divide to 0!!!"); double?reserv = UserNumbers[0]; UserNumbers = new double?[UserNumbersCount + 1] { null, null, null }; UserNumbers[0] = reserv; continue; } switch (SelectedVariant) { case CalculatorVariant.Addition: UserNumbers[2] = UserNumbers[0] + UserNumbers[1]; break; case CalculatorVariant.Divide: UserNumbers[2] = UserNumbers[0] / UserNumbers[1]; break; case CalculatorVariant.Multiplication: UserNumbers[2] = UserNumbers[0] * UserNumbers[1]; break; case CalculatorVariant.Subtraction: UserNumbers[2] = UserNumbers[0] - UserNumbers[1]; break; case CalculatorVariant.Exponentiation: UserNumbers[2] = Math.Pow((double)UserNumbers[0], (double)UserNumbers[1]); break; } ShowResult(UserNumbers[0] + " " + GetSymbol(SelectedVariant) + " " + UserNumbers[1] + " = " + UserNumbers[2]); ShowTheCondition(); break; } } }
public override void Run() { Console.Clear(); ShowTheCondition(); string UserAnswer; FermerVariant SelectedVariant; Coast coast1 = new Coast(true); Coast coast2 = new Coast(); FarmerProperty?farmerProperty; while (true) { UserAnswer = AskUser("Please, type numbers by step (0 to repeat the rules)"); if (UserAnswer.ToLower() == "q") { return; } else if (!Enum.TryParse(UserAnswer, out SelectedVariant) || !Enum.IsDefined(typeof(FermerVariant), SelectedVariant)) { continue; } if (SelectedVariant == FermerVariant.Repeat) { ShowTheCondition(); continue; } if (ProhibitedAction(coast1, coast2, SelectedVariant)) { continue; } switch (SelectedVariant) { case FermerVariant.ThereFarmer: case FermerVariant.BackFarmer: farmerProperty = null; break; case FermerVariant.ThereFarmerAndWolf: case FermerVariant.BackFarmerAndWolf: farmerProperty = FarmerProperty.wolf; break; case FermerVariant.ThereFarmerAndGoat: case FermerVariant.BackFarmerAndGoat: farmerProperty = FarmerProperty.goat; break; case FermerVariant.ThereFarmerAndCabbage: case FermerVariant.BackFarmerAndCabbage: farmerProperty = FarmerProperty.cabbage; break; case FermerVariant.ShowFirstCoast: coast1.ShowCoast(); continue; case FermerVariant.ShowSecondCoast: coast2.ShowCoast(); continue; default: ShowError("unknown error, try again"); continue; } if (coast1.StepCheck(farmerProperty) && coast2.StepCheck(farmerProperty)) { coast1.StepRun(farmerProperty); coast2.StepRun(farmerProperty); forReturn = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Step was success"); Console.ForegroundColor = forReturn; if (coast2.AllIn()) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("You WIN!!!"); Console.ReadLine(); return; } } } }