Last active
April 5, 2023 13:03
-
-
Save sammysheep/8799bc4544dca3601f3aa3650213bdb5 to your computer and use it in GitHub Desktop.
SmithClass-SumArray
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sam Shepard - 2023 | |
// SumArray - add numbers to a List until we are given the word "STOP" | |
// Creates the sum and the average of the array entered. | |
List<int> my_power_levels = new List<int>(); | |
while (true) | |
{ | |
Console.Write("Enter a power level ('STOP' to stop): "); | |
string? input = Console.ReadLine(); | |
// For the "condition", stop if empty or any casing of the word stop | |
if (String.IsNullOrWhiteSpace(input) || input.ToUpper() == "STOP") | |
{ | |
break; | |
} | |
else | |
{ | |
my_power_levels.Add(Convert.ToInt32(input)); | |
} | |
} | |
// Sum the array | |
// YOUR SUM OF THE ARRAY HERE USING FOREACH! | |
// Compute the average! | |
double count = my_power_levels.Count; | |
// CALCULATE AVERAGE HERE! | |
Console.WriteLine($"The sum of {count} power entered is {sum}"); | |
Console.WriteLine($"The average power level was: {average}"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment