From 776efa1e79d50a6a0dc85535e667f5cdef12e433 Mon Sep 17 00:00:00 2001 From: "James.Woodard" Date: Mon, 30 Jul 2018 09:22:04 -0500 Subject: [PATCH 1/3] started over on the FUCKING CHECKPOINT BECAUSE IM AN IDIOT AND OVERWROTE IT --- Checkpoint1/.vscode/launch.json | 28 ++++++++++++++++++++++ Checkpoint1/.vscode/tasks.json | 15 ++++++++++++ Checkpoint1/Checkpoint1.cs | 41 ++++++++++++++++++++++++++++++++- 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 Checkpoint1/.vscode/launch.json create mode 100644 Checkpoint1/.vscode/tasks.json diff --git a/Checkpoint1/.vscode/launch.json b/Checkpoint1/.vscode/launch.json new file mode 100644 index 00000000..bb71d335 --- /dev/null +++ b/Checkpoint1/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/Checkpoint1.dll", + "args": [], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window + "console": "internalConsole", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ,] +} \ No newline at end of file diff --git a/Checkpoint1/.vscode/tasks.json b/Checkpoint1/.vscode/tasks.json new file mode 100644 index 00000000..65947bdb --- /dev/null +++ b/Checkpoint1/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/Checkpoint1.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/Checkpoint1/Checkpoint1.cs b/Checkpoint1/Checkpoint1.cs index b7ed8611..89aeaebb 100644 --- a/Checkpoint1/Checkpoint1.cs +++ b/Checkpoint1/Checkpoint1.cs @@ -1,4 +1,7 @@ using System; +using System.Linq; +using System.Collections; +using System.Collections.Generic; namespace Checkpoint1 { @@ -6,7 +9,43 @@ class Program { static void Main(string[] args) { - Console.WriteLine("Hello World!"); + void MainMenu(){ + + + } + + + // 1- Write a program to count how many numbers between 1 and 100 are divisible by 3 with no remainder. Display the count on the console. + void Problem1(){ + + + } + + + // 2- Write a program and continuously ask the user to enter a number or "ok" to exit. Calculate the sum of all the previously entered numbers and display it on the console. + void Problem2(){ + int playerChoice = 0; + Console.WriteLine("Please enter a number, or hit OK if you are done entering numbers"); + } + + + // 3- Write a program and ask the user to enter a number. Compute the factorial of the number and print it on the console. For example, if the user enters 5, the program should calculate 5 x 4 x 3 x 2 x 1 and display it as 5! = 120. + void problem3(){ + + + } + + // 4- Write a program that picks a random number between 1 and 10. Give the user 4 chances to guess the number. If the user guesses the number, display “You won"; otherwise, display “You lost". (To make sure the program is behaving correctly, you can display the secret number on the console first.) + void problem4(){ + + + } + + // 5- Write a program and ask the user to enter a series of numbers separated by comma. Find the maximum of the numbers and display it on the console. For example, if the user enters “5, 3, 8, 1, 4", the program should display 8. + void problem5(){ + + + } } } } From 8344087f3e86c8ce75eef76665f0627373e1a3ca Mon Sep 17 00:00:00 2001 From: "James.Woodard" Date: Mon, 30 Jul 2018 11:40:32 -0500 Subject: [PATCH 2/3] completely redid checkpoint 1 cuz im a fuckin retard --- Checkpoint1/Checkpoint1.cs | 169 +++++++++++++++++++++++++++++++++++-- 1 file changed, 163 insertions(+), 6 deletions(-) diff --git a/Checkpoint1/Checkpoint1.cs b/Checkpoint1/Checkpoint1.cs index 89aeaebb..c8a7d0dd 100644 --- a/Checkpoint1/Checkpoint1.cs +++ b/Checkpoint1/Checkpoint1.cs @@ -9,14 +9,67 @@ class Program { static void Main(string[] args) { + + MainMenu(); + + int userChoice = 0; void MainMenu(){ + Console.WriteLine("Welcome to Checkpoint 1. Please select a choice:"); + Console.WriteLine("1. Divisible by 3 tool"); + Console.WriteLine("2. Addition tool"); + Console.WriteLine("3. Factorial tool"); + Console.WriteLine("4. Guess a number"); + Console.WriteLine("5. Find largest number"); + if (Int32.TryParse(Console.ReadLine(), out userChoice)) + { + if (userChoice == 1) + { + Problem1(); + } + else if (userChoice == 2) + { + Problem2(); + } + else if (userChoice == 3) + { + Problem3(); + } + else if (userChoice == 4) + { + Problem4(); + } + else if (userChoice == 5) + { + Problem5(); + } + else + { + Console.WriteLine("That was an invalid choice"); + MainMenu(); + } + } + else + { + Console.WriteLine("That was an invalid choice"); + MainMenu(); + } } // 1- Write a program to count how many numbers between 1 and 100 are divisible by 3 with no remainder. Display the count on the console. void Problem1(){ + int divisibleCount = 0; + for (int i = 1; i <= 100; i++) + { + if (i % 3 == 0) + { + divisibleCount++; + Console.WriteLine(i + " is divisible by 3. That makes " + divisibleCount + " numbers so far that are divisible by 3."); + } + } + Console.WriteLine("Counting done. There are " + divisibleCount + "numbers between 1 and 100 that are divisble by 3."); } @@ -25,24 +78,128 @@ void Problem1(){ // 2- Write a program and continuously ask the user to enter a number or "ok" to exit. Calculate the sum of all the previously entered numbers and display it on the console. void Problem2(){ int playerChoice = 0; - Console.WriteLine("Please enter a number, or hit OK if you are done entering numbers"); + List numbers = new List(); + GetNumber(); + + void GetNumber(){ + Console.WriteLine("Please enter a number, or type ok if you are done entering numbers"); + string input = Console.ReadLine(); + if (Int32.TryParse(input, out playerChoice)) + { + numbers.Add(playerChoice); + GetNumber(); + } + else if (input == "ok") + { + int sum = numbers.Sum(); + Console.WriteLine("The sum of the numbers you entered is " + sum); + MainMenu(); + } + else + { + Console.WriteLine("Your choice was invalid." ); + GetNumber(); + } + } } // 3- Write a program and ask the user to enter a number. Compute the factorial of the number and print it on the console. For example, if the user enters 5, the program should calculate 5 x 4 x 3 x 2 x 1 and display it as 5! = 120. - void problem3(){ + void Problem3(){ + int userNumber = 0; + int i = 0; + + Console.WriteLine("Enter a number: "); + // userNumber = int.Parse(Console.ReadLine()); + if (Int32.TryParse((Console.ReadLine()), out userNumber)) + { + int factorial = userNumber; + for (i = userNumber - 1; i >= 1; i--) + { + factorial = factorial * i; + } + Console.WriteLine("The factorial of " + userNumber + " is " + factorial); + Console.ReadLine(); + MainMenu(); + } + else + { + Console.WriteLine("Your choice was invalid." ); + Problem3(); + } } // 4- Write a program that picks a random number between 1 and 10. Give the user 4 chances to guess the number. If the user guesses the number, display “You won"; otherwise, display “You lost". (To make sure the program is behaving correctly, you can display the secret number on the console first.) - void problem4(){ + void Problem4(){ + int chances = 4; + int guess = 0; + Random rnd = new Random(); + int compChoice = rnd.Next(1, 10); - - } + GuessingTime(); + void GuessingTime(){ + Console.WriteLine("The computer mastermind has chosen a number between 1 and 10. Can you guess it correctly?"); + while (chances > 0) + { + Console.WriteLine("Type a number between 1 and 10 and press Enter"); + if (Int32.TryParse((Console.ReadLine()), out guess)) + { + if ((guess > 10) || (guess < 1 )) + { + Console.WriteLine("Your selection is invalid."); + Problem4(); + } + else if (guess == compChoice) + { + Console.WriteLine("You guessed right with " + chances + " chances left! You win!"); + MainMenu(); + } + else + { + chances--; + Console.WriteLine("You guessed wrong! You have " + chances + " chances left!"); + + } + + } + else + { + Console.WriteLine("Your choice was invalid." ); + Problem4(); + } + } + Console.WriteLine("You ran out of guesses! You lose! The computer mastermind's number was " + compChoice); + MainMenu(); + } + + } // 5- Write a program and ask the user to enter a series of numbers separated by comma. Find the maximum of the numbers and display it on the console. For example, if the user enters “5, 3, 8, 1, 4", the program should display 8. - void problem5(){ + void Problem5(){ + Console.WriteLine("Input a bunch of numbers separated by commas, then press enter"); + string input = Console.ReadLine(); + + string[] numbers = (input).Split(","); + int[] numbersInt = new int[numbers.Length]; + + for (int i = 0; i < numbers.Length; i++) + { + if (Int32.TryParse(numbers[i], out numbersInt[i])) + { + + } + else + { + Console.WriteLine("One of your inputs was invalid, please try again"); + Problem5(); + } + + } + Console.WriteLine("The largest number you entered is " + numbersInt.Max()); + MainMenu(); + } From c1513171283a1e633c5462eb5242cd1c293b6ff9 Mon Sep 17 00:00:00 2001 From: "James.Woodard" Date: Mon, 30 Jul 2018 21:20:47 -0500 Subject: [PATCH 3/3] cleaned up code on chkpt1 --- Checkpoint1/Checkpoint1.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Checkpoint1/Checkpoint1.cs b/Checkpoint1/Checkpoint1.cs index c8a7d0dd..c66223d7 100644 --- a/Checkpoint1/Checkpoint1.cs +++ b/Checkpoint1/Checkpoint1.cs @@ -70,8 +70,7 @@ void Problem1(){ } } Console.WriteLine("Counting done. There are " + divisibleCount + "numbers between 1 and 100 that are divisble by 3."); - - + MainMenu(); } @@ -119,7 +118,6 @@ void Problem3(){ factorial = factorial * i; } Console.WriteLine("The factorial of " + userNumber + " is " + factorial); - Console.ReadLine(); MainMenu(); } else @@ -171,7 +169,7 @@ void GuessingTime(){ Problem4(); } } - Console.WriteLine("You ran out of guesses! You lose! The computer mastermind's number was " + compChoice); + Console.WriteLine("You ran out of guesses! You lose! The computer mastermind's number was " + compChoice + "! You have perished."); MainMenu(); }