From 2bbcf94b3ecf2b1cef71c872fe1dd2c167be45af Mon Sep 17 00:00:00 2001 From: Andy Fogarasi Date: Fri, 19 Apr 2019 17:41:02 -0500 Subject: [PATCH 1/2] FizzBuzz --- FizzBuzz/FizzBuzz.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/FizzBuzz/FizzBuzz.cs b/FizzBuzz/FizzBuzz.cs index 9246f703..b496f557 100644 --- a/FizzBuzz/FizzBuzz.cs +++ b/FizzBuzz/FizzBuzz.cs @@ -7,6 +7,30 @@ class Program static void Main(string[] args) { Console.WriteLine("Hello World!"); + + // This is FizzBuzz + // Count from 0 to 100 + // If the the count number is divisble by 5 and 3 (15) without a remainder print "FizzBuzz" + // If the the count number is divisble by 5 without a remainder print "Buzz" + // If the the count number is divisble by 3 without a remainder print "Fizz" + // If none of the above apply, print out the number + + for (int i = 1; i <= 100; i++) + { + if ( (i - ((i / 15) * 15)) == 0) { + Console.WriteLine("FizzBuzz"); + } + else if ( (i - ((i / 5) * 5)) == 0) { + Console.WriteLine("Buzz"); + } + else if ( (i - ((i / 3) * 3)) == 0) { + Console.WriteLine("Fizz"); + } + else { + Console.WriteLine(i); + } + } + } } } From ff2a0d0476d1f3b7f19b290a9f16d7829b7b34ba Mon Sep 17 00:00:00 2001 From: Andy Fogarasi Date: Tue, 23 Apr 2019 12:08:57 -0500 Subject: [PATCH 2/2] Checkpoint 1 Complete --- Checkpoint1/Checkpoint1.cs | 156 ++++++++++++++++++++++++++++++++++++- 1 file changed, 155 insertions(+), 1 deletion(-) diff --git a/Checkpoint1/Checkpoint1.cs b/Checkpoint1/Checkpoint1.cs index b7ed8611..99affcd7 100644 --- a/Checkpoint1/Checkpoint1.cs +++ b/Checkpoint1/Checkpoint1.cs @@ -1,12 +1,166 @@ using System; +using System.Collections.Generic; namespace Checkpoint1 { class Program { + public static bool end = false; + static void Main(string[] args) { - Console.WriteLine("Hello World!"); + // Create 5 different Modules with the functionality below for a user to access via the console + // Module 1 - counts numbers between 1 and 100 and display the numbers evenly divisible by three + // Module 2 - ask user to enter a number, then again or "ok" to end the entry. Upon "ok" all numbers are summed and displayed + // Module 3 - ask user to enter a number. return and display the factorial as "var! = var factorial" + // Module 4 - computer generate a random number between 1 and 10. Ask user to guess the number. Correct guess = "You win/loose". User has 4 chances + // Module 5 = ask user to enter a series of numbers separated by commas. Find the largest number and display it to the console. + + // Allow user to choose which Module to execute. Continue asking until user chooses any invalid option + do { + Console.WriteLine("Execute one of the following by entering the cooresponding number"); + Console.WriteLine("Enter 1 to display all numbers from 1-100 divisible by three"); + Console.WriteLine("Enter 2 to get the sum of a series of numbers you enter"); + Console.WriteLine("Enter 3 to get the factorial of a number you enter"); + Console.WriteLine("Enter 4 to try and guess the computer chosen number between 1 and 10"); + Console.WriteLine("Enter 5 to find the largest number in a series of numbers you enter"); + Console.WriteLine("Any other choice to exit"); + int choice = int.Parse(Console.ReadLine()); + + if (choice == 1) { + NumbersbyThree(); + } + else if (choice == 2) { + SumofNumbers(); + } + else if (choice == 3) { + Factorial(); + } + else if (choice == 4) { + GuessaNumber(); + } + else if (choice == 5) { + MaxNumber(); + } + else { + Console.WriteLine("Ending Exercise"); + end = true; + } + } while (!EndExercise() == true ); + // leave this command at the end so your program does not close automatically + Console.ReadLine(); + } + + // Module 1 - counts numbers between 1 and 100 and display the numbers evenly divisible by three + public static void NumbersbyThree() + { + Console.WriteLine("Numbers by Three"); + List threeList = new List(); + for (int i = 1; i <= 100; i++) + if ( (i - ((i / 3) * 3)) == 0) { + Console.WriteLine(i); + threeList.Add(i); + } + Console.WriteLine("Count of numbers divisible by 3: " +threeList.Count); + } + + // Module 2 - ask user to enter a number, then again or "ok" to end the entry. Upon "ok" all numbers are summed and displayed + public static void SumofNumbers() + { + Console.WriteLine("Sum of Numbers"); + int sum1 = 0; + bool endSum = false; + do { + // ask user to input a number or "ok" to end + Console.WriteLine("Enter a number or type \"ok\" when finished"); + string userInput = (Console.ReadLine().ToLower()); + // check to see if user enters "ok" + if (userInput == "ok") { + endSum = true; + } + // if user enters another number add it to the other numbers + else sum1 = sum1 + int.Parse(userInput); + } while (endSum != true); + // if user has finished entering numbers print the sum of the numbers to the console + Console.WriteLine("Sum of Numbers: " + sum1); } + + // Module 3 - ask user to enter a number. return and display the factorial as "var! = var factorial" + public static void Factorial() + { + Console.WriteLine("Enter a number to find its factorial: "); + int f1 = int.Parse(Console.ReadLine()); + int origNum = f1; + for (int i = f1 - 1; i >= 1; i--){ + f1 = f1 * i; + } + Console.WriteLine(origNum +"! = " +f1); + } + + // Module 4 - computer generate a random number between 1 and 10. Ask user to guess the number. Correct guess = "You win/loose". User has 4 chances + public static void GuessaNumber() + { + // ask user to enter a number. save the number. + Console.WriteLine("Can you guess the computers number in four tries? Enter a number between 1 and 10: "); + int userGuess = int.Parse(Console.ReadLine()); + // computer generate a random number between 1 and 10. save the number. + Random rnd = new Random(); + int compGuess = rnd.Next(1, 10); + bool winCheck = false; + bool countCheck = false; + int count1 = 1; + // check if user number matches computer number OR if user has used four tries + while (winCheck == false && countCheck == false){ + count1 = count1 + 1; + // if user number matches computer number write "you win" to the console. exit exercise. + if (userGuess == compGuess) { + winCheck = true; + Console.WriteLine("They Match. You WIN!"); + } + // if user number does not match computer number ask user for another number + else { + Console.WriteLine("No Match. Enter a different number: "); + userGuess = int.Parse(Console.ReadLine()); + // if user has used all four tries without matching the computer, write "you loose" to the console. exit exercise. + if (count1 >=4) { + countCheck = true; + Console.WriteLine("Four tries. No Match. You Loose."); + } + } + } + + } + + // Module 5 = ask user to enter a series of numbers separated by commas. Find the largest number and display it to the console. + public static void MaxNumber() + { + // Ask user for a series of integers separated by commas. save the input. + Console.WriteLine("Enter a series of integers separated by commas. Cumputer will return the largest number: "); + string all = Console.ReadLine(); + string[] Section = all.Split(","); + List numList = new List(); + int eachNum; + int largest = 0; + // Separate the string using the "," and save as a list of integers + foreach(string eachSect in Section){ + if(Int32.TryParse(eachSect, out eachNum)) + numList.Add(eachNum); + } + // Find the largest integer in the list and save it + foreach (int num in numList){ + if (num > largest) { + largest = num; + } + } + // Print largest number to screen + Console.WriteLine ("Max Number is: " +largest); + } + + // Check for end of exercise + public static bool EndExercise() + { + return end; + + } } }