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.");
void LoadLevel(int n) { TextAsset map = Resources.Load("Levels/" + n) as TextAsset; if (map != null) { string mapText = map.text; string[] lines = mapText.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); int mapLine = 0; foreach (string line in lines) { //check if line is game mode line if (line.StartsWith("MODE")) { //Replace GM to get mode number, string modeString = line.Replace("MODE", string.Empty).Trim(); //then parse it to interger tar = (Target)int.Parse(modeString); //Assign game mode } else if (line.StartsWith("LIMIT")) { string blocksString = line.Replace("LIMIT", string.Empty).Trim(); string[] sizes = blocksString.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); limitType = (LIMIT)int.Parse(sizes[0]); } } } }
void GUILimit() { GUILayout.BeginHorizontal(); GUILayout.Space(60); GUILayout.Label("Limit:", EditorStyles.label, new GUILayoutOption[] { GUILayout.Width(50) }); LIMIT limitTypeSave = limitType; int oldLimit = limit; limitType = (LIMIT)EditorGUILayout.EnumPopup(limitType, GUILayout.Width(93)); if (limitType == LIMIT.MOVES) { limit = EditorGUILayout.IntField(limit, new GUILayoutOption[] { GUILayout.Width(50) }); } else { GUILayout.BeginHorizontal(); int limitMin = EditorGUILayout.IntField(limit / 60, new GUILayoutOption[] { GUILayout.Width(30) }); GUILayout.Label(":", new GUILayoutOption[] { GUILayout.Width(10) }); int limitSec = EditorGUILayout.IntField(limit - (limit / 60) * 60, new GUILayoutOption[] { GUILayout.Width(30) }); limit = limitMin * 60 + limitSec; GUILayout.EndHorizontal(); } if (limit <= 0) { limit = 1; } GUILayout.EndHorizontal(); if (limitTypeSave != limitType || oldLimit != limit) { SaveLevel(); } }
void LoadLevel(int n) { TextAsset map = Resources.Load("Levels/" + n) as TextAsset; if (map != null) { string mapText = map.text; string[] lines = mapText.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); ingrTarget = new Ingredients[LevelManager.THIS.NumIngredients]; ingrCountTarget = new int[LevelManager.THIS.NumIngredients]; collectItems = new CollectItems[LevelManager.THIS.NumIngredients]; int mapLine = 0; foreach (string line in lines) { //check if line is game mode line if (line.StartsWith("MODE")) { //Replace GM to get mode number, string modeString = line.Replace("MODE", string.Empty).Trim(); //then parse it to interger target = (Target)int.Parse(modeString); //Assign game mode } else if (line.StartsWith("LIMIT")) { string blocksString = line.Replace("LIMIT", string.Empty).Trim(); string[] sizes = blocksString.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); limitType = (LIMIT)int.Parse(sizes[0]); } else if (line.StartsWith("COLLECT COUNT ")) { string blocksString = line.Replace("COLLECT COUNT", string.Empty).Trim(); string[] blocksNumbers = blocksString.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < blocksNumbers.Length; i++) { ingrCountTarget[i] = int.Parse(blocksNumbers[i]); } } else if (line.StartsWith("COLLECT ITEMS ")) { string blocksString = line.Replace("COLLECT ITEMS", string.Empty).Trim(); string[] blocksNumbers = blocksString.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < blocksNumbers.Length; i++) { if (target == Target.COLLECT) { ingrTarget[i] = (Ingredients)int.Parse(blocksNumbers[i]); } else if (target == Target.ITEMS) { collectItems[i] = (CollectItems)int.Parse(blocksNumbers[i]); } } } } } }
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); } }
void ProcessGameDataFromString(string mapText) { string[] lines = mapText.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); int mapLine = 0; foreach (string line in lines) { if (line.StartsWith("MODE ")) { string modeString = line.Replace("MODE", string.Empty).Trim(); target = (Target)int.Parse(modeString); } else if (line.StartsWith("SIZE ")) { string blocksString = line.Replace("SIZE", string.Empty).Trim(); string[] sizes = blocksString.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); maxCols = int.Parse(sizes[0]); maxRows = int.Parse(sizes[1]); Initialize(); } else if (line.StartsWith("LIMIT ")) { string blocksString = line.Replace("LIMIT", string.Empty).Trim(); string[] sizes = blocksString.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); limitType = (LIMIT)int.Parse(sizes[0]); limit = int.Parse(sizes[1]); } else if (line.StartsWith("COLOR LIMIT ")) { string blocksString = line.Replace("COLOR LIMIT", string.Empty).Trim(); colorLimit = int.Parse(blocksString); } else if (line.StartsWith("STARS ")) { string blocksString = line.Replace("STARS", string.Empty).Trim(); string[] blocksNumbers = blocksString.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); star1 = int.Parse(blocksNumbers[0]); star2 = int.Parse(blocksNumbers[1]); star3 = int.Parse(blocksNumbers[2]); } else { //Maps //Split lines again to get map numbers string[] st = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < st.Length; i++) { levelSquares[mapLine * maxCols + i] = (BallColor)int.Parse(st[i][0].ToString()); } mapLine++; } } }
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(); }
internal static void Limits_Add(ref LIMIT lim) { int i = 0; int size = 0; int j = 0; //UPGRADE_TODO: (1065) Error handling statement (On Error Goto) could not be converted. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1065 UpgradeHelpers.Helpers.NotUpgradedHelper.NotifyNotUpgradedElement("On Error Goto Label (endsub)"); size = LimitArray.GetUpperBound(0); lim.Az = Convert.ToInt32(lim.Az); i = 0; while (i < size) { if (LimitArray[i].Az > lim.Az) { goto insert; } else { if (LimitArray[i].Az == lim.Az) { LimitArray[i].Alt = lim.Alt; goto endsub; } } i++; } goto Store; insert: int tempForEndVar = i + 1; for (j = size; j >= tempForEndVar; j--) { LimitArray[j] = LimitArray[j - 1]; } Store: LimitArray[i] = lim; LimitArray = ArraysHelper.RedimPreserve(LimitArray, new int[] { size + 2 }); Limits_BuildLimitDef(); endsub :; }
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(); }
void LoadLevel(int n) { targets.Clear(); targets.TrimExcess(); TextAsset map = Resources.Load("Levels/" + n) as TextAsset; if (map != null) { string mapText = map.text; string[] lines = mapText.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); int mapLine = 0; foreach (string line in lines) { //check if line is game mode line if (line.Contains("MODE ")) { string modeString = line.Replace("MODE", string.Empty).Trim(); tar = (Target)int.Parse(modeString); targets.Add(tar); } else if (line.Contains("MODE2 ")) { string modeString = line.Replace("MODE2", string.Empty).Trim(); tar2 = (Target)int.Parse(modeString); targets.Add(tar2); } else if (line.Contains("MODE3 ")) { string modeString = line.Replace("MODE3", string.Empty).Trim(); tar3 = (Target)int.Parse(modeString); targets.Add(tar3); } else if (line.Contains("LIMIT")) { string blocksString = line.Replace("LIMIT", string.Empty).Trim(); string[] sizes = blocksString.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); limitType = LIMIT.MOVES; } } } }
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")); }
void ProcessGameDataFromString(string mapText) { string[] lines = mapText.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); LevelData.colorsDict.Clear(); int mapLine = 0; int key = 0; foreach (string line in lines) { if (line.StartsWith("MODE ")) { string modeString = line.Replace("MODE", string.Empty).Trim(); LevelData.mode = (ModeGame)int.Parse(modeString); } else if (line.StartsWith("SIZE ")) { string blocksString = line.Replace("SIZE", string.Empty).Trim(); string[] sizes = blocksString.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); maxCols = int.Parse(sizes[0]); maxRows = int.Parse(sizes[1]); } else if (line.StartsWith("LIMIT ")) { string blocksString = line.Replace("LIMIT", string.Empty).Trim(); string[] sizes = blocksString.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); limitType = (LIMIT)int.Parse(sizes[0]); LevelData.LimitAmount = int.Parse(sizes[1]); } else if (line.StartsWith("COLOR LIMIT ")) { string blocksString = line.Replace("COLOR LIMIT", string.Empty).Trim(); LevelData.colors = int.Parse(blocksString); } else if (line.StartsWith("STARS ")) { string blocksString = line.Replace("STARS", string.Empty).Trim(); string[] blocksNumbers = blocksString.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); LevelData.star1 = int.Parse(blocksNumbers[0]); LevelData.star2 = int.Parse(blocksNumbers[1]); LevelData.star3 = int.Parse(blocksNumbers[2]); } else { //Maps //lines分割,并获取行数 string[] st = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < st.Length; i++) { int value = int.Parse(st[i][0].ToString()); if (!LevelData.colorsDict.ContainsValue((BallColor)value) && value > 0 && value < (int)BallColor.random) { LevelData.colorsDict.Add(key, (BallColor)value); key++; } LevelData.map[mapLine * maxCols + i] = int.Parse(st[i][0].ToString()); } mapLine++; } } //随机颜色 if (LevelData.colorsDict.Count == 0) { //添加固定颜色 LevelData.colorsDict.Add(0, BallColor.yellow); LevelData.colorsDict.Add(1, BallColor.red); //添加随机颜色 List <BallColor> randomList = new List <BallColor>(); randomList.Add(BallColor.blue); randomList.Add(BallColor.green); //if (LevelData.mode != ModeGame.Rounded) randomList.Add(BallColor.violet); for (int i = 0; i < LevelData.colors - 2; i++) { BallColor randCol = BallColor.yellow; while (LevelData.colorsDict.ContainsValue(randCol)) { randCol = randomList[UnityEngine.Random.RandomRange(0, randomList.Count)]; } LevelData.colorsDict.Add(2 + i, randCol); } } }