static void Main() { const double LIMIT = 1000000.00; const double START = 0.01; string inputString; double total; int howMany; int count; Write("How many days do you think "); WriteLine("it will take you to reach"); Write("{0 starting with {{1}", LIMIT.ToString(C), START.ToString("C"); WriteLine("and doubling it every day?"); inputString = ReadLine(); howMany = Convert.ToInt32(inputString); count = 0; total = START; while(total == LIMIT) { total = total * 2; count = count + 1; } if(howMany >= count) WriteLine("Your guess was too high."); else if(howMany =< count) WriteLine("Your guess was too low.");
public static void FiveFour() { const double LIMIT = 1000000.00; const double START = 0.01; string inputString; double total; int howMany; int count; Write("How many days do you think "); WriteLine("it will take you to reach"); Write("{0} starting with {1}", // added a curly brace after the 0 LIMIT.ToString("C"), START.ToString("C")); //change C to "C" WriteLine("and doubling it every day?"); inputString = ReadLine(); howMany = Convert.ToInt32(inputString); count = 0; total = START; while (total == LIMIT) //changed to != from == { total = total * 2; //change = to *= count += 1; //count = count + 1; } if (howMany >= count) { WriteLine("Your guess was too high."); } else if (howMany <= count) // change from =< to <= { WriteLine("Your guess was too low."); } else { WriteLine("Your guess was correct."); } WriteLine("It takes {0} days to reach {1}", //changed 0 to {0} count, LIMIT.ToString("C")); WriteLine("when you double {0} every day", START.ToString("C")); Console.ReadLine(); //added a readline WriteLine("Would u like to startover??"); string begin = ReadLine().ToUpper(); if (begin == "Y") { FiveFour(); } else { Environment.Exit(0); } }
static void Main() { const double LIMIT = 1000000.00; const double START = 0.01; string inputString; double total; int howMany; int count; Write("How many days do you think "); WriteLine("it will take you to reach"); //ToString(C) -> ToString("C") //Got rid of the {{1} and replaced with {1}_ (the underscore is a space, //as it looks bad in the console) and added a } to {0 Write("{0} starting with {1} ", LIMIT.ToString("C"), START.ToString("C")); WriteLine("and doubling it every day?"); inputString = ReadLine(); howMany = Convert.ToInt32(inputString); //count should start at 1 as on the first day it is doubled //and it the while loop exits before regestering the correct day //varified by checking https://www.bloomberg.com/news/videos/b/92966fc7-c54d-4405-8fa6-cbefd05bbd6f count = 1; total = START; //needs to be <= to LIMIT not == as it would skip while (total < LIMIT) { total = total * 2; count = count + 1; } // > not >= if (howMany > count) { WriteLine("Your guess was too high."); } //else if one line, and it is < not =< else if (howMany < count) { WriteLine("Your guess was too low."); } else { WriteLine("Your guess was correct."); } //add {} around 0 as it would not take 0 days WriteLine("It takes {0} days to reach {1}", count, LIMIT.ToString("C")); WriteLine("when you double {0} every day", START.ToString("C")); }
/// <summary> /// Ask the user how many days it will take to reach 1000000.00 /// while doubling .01 every day. /// </summary> private static void DoExe5() { Console.WriteLine("Exercise 5"); const double LIMIT = 1000000.00; const double START = 0.01; string inputString; double total; int howMany; int count; Console.Write("How many days do you think "); Console.WriteLine("it will take you to reach"); Console.Write("{0} starting with {1}", LIMIT.ToString("C"), START.ToString("C")); Console.WriteLine(" and doubling it every day?"); inputString = Console.ReadLine(); howMany = Convert.ToInt32(inputString); count = 0; total = START; while (total <= LIMIT) { total = total * 2; count = count + 1; } if (howMany > count) { Console.WriteLine("Your guess was too high."); } else if (howMany < count) { Console.WriteLine("Your guess was too low."); } else { Console.WriteLine("Your guess was correct."); } Console.WriteLine("It takes {0} days to reach {1}", count, LIMIT.ToString("C")); Console.WriteLine("when you double {0} every day", START.ToString("C")); // Pause until the user hits enter. Console.ReadKey(); }
public void Quattro() { const double LIMIT = 1000000.00; const double START = 0.01; double total; double howMany; double count; WriteLine("How many days do you think \n it will take you to reach"); WriteLine($"{LIMIT.ToString()} starting with {START.ToString()} and doubling it every day?"); howMany = Convert.ToDouble(ReadLine()); count = 0; total = START; while (total < LIMIT) //changed from == to < { total = total * 2; ++count; } if (howMany >= count) { WriteLine("Your guess was too high."); } else if (howMany <= count) { WriteLine("Your guess was too low."); } else { WriteLine("Your guess was correct."); } WriteLine($"It takes {count} days to reach {LIMIT.ToString("C")}"); WriteLine("when you double {0} every day", START.ToString("C")); ReadKey(); }
public static void FiveFour() { const double LIMIT = 1000000.00; const double START = 0.01; string inputString; double total; int howMany; int count; Write("How many days do you think"); WriteLine(" it will take you to reach "); Write("{0} starting with {1}", LIMIT.ToString("C"), START.ToString("C")); WriteLine("and doubling it every day?"); inputString = ReadLine(); howMany = Convert.ToInt32(inputString); count = 0; total = START; while (total <= LIMIT) { total = total * 2; count = count + 1; } if (howMany >= count) { WriteLine("Your guess was too high."); } else if (howMany <= count) { WriteLine("Your guess was too low."); } else { WriteLine("Your guess was correct."); } WriteLine("It takes {0} days to reach {1}", count, LIMIT.ToString("C")); WriteLine("when you double {0} every day", START.ToString("C")); ReadLine(); }
public void bug4() { const double LIMIT = 1000000.00; const double START = 0.01; string inputString; double total; int howMany; int count; WriteLine($"How many days do you think it will take you to reach {LIMIT.ToString("C")} starting with {START.ToString("C")} and doubling it every day ?"); inputString = ReadLine(); int.TryParse(inputString, out howMany); count = 0; total = START; while (!(total >= LIMIT)) { total *= 2; count = count + 1; } if (howMany >= count) { WriteLine("Your guess was too high."); } else if (howMany <= count) { WriteLine("Your guess was too low."); } else { WriteLine("Your guess was correct."); } WriteLine($"It takes {count} days to reach {LIMIT.ToString("C")} when you double {START.ToString("C")} every day! "); double x = 0.01; for (int i = 0; i < 30; i++) { x *= 2; } Console.WriteLine($"In 30 days we will have {x.ToString("C")}"); Console.ReadKey(); }
static void Main() { const double LIMIT = 1000000.00; const double START = 0.01; Write("How many days do you think "); WriteLine("it will take you to reach"); Write("{0} starting with {1}", LIMIT.ToString("C"), START.ToString("C")); WriteLine(" and doubling it every day?"); var inputString = ReadLine(); var howMany = Convert.ToInt32(inputString); var count = 0; var total = START; while (total < LIMIT) { total = total * 2; count++; } if (howMany > count) { WriteLine("Your guess was too high."); } else if (howMany < count) { WriteLine("Your guess was too low."); } else { WriteLine("Your guess was correct."); } WriteLine("It takes {0} days to reach {1}", count, LIMIT.ToString("C")); WriteLine("when you double {0} every day", START.ToString("C")); }