Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Program
- {
- private static int[] scores;
- public static void Main(string[] args)
- {
- scores = new int[0];
- int selection = 0;
- do
- {
- selection = UserMenu();
- if (selection == 1)
- {
- SelectionOne();
- }
- else if (selection == 2)
- {
- SelectionTwo();
- }
- else if (selection == 3)
- {
- SelectionThree();
- }
- }
- while (selection != 4);
- }
- public static int UserMenu()
- {
- Console.WriteLine("________Menu________");
- Console.WriteLine("1) enter scores");
- Console.WriteLine("2) list scores");
- Console.WriteLine("3) calculate statistics");
- Console.WriteLine("4) exit");
- Console.WriteLine("_____________________");
- Console.WriteLine("Make a selection (1-4)");
- return Convert.ToInt32(Console.ReadLine());
- }
- public static void SelectionOne()
- {
- Console.WriteLine("How many scores do you want to enter?");
- int scoreCount = Convert.ToInt32(Console.ReadLine());
- scores = new int[scoreCount];
- for (int i = 0; i < scores.Length; i++)
- {
- Console.WriteLine("Enter a score:");
- scores[i] = Convert.ToInt32(Console.ReadLine());
- }
- }
- public static void SelectionTwo()
- {
- Console.WriteLine("___Scores___");
- foreach (int score in scores)
- {
- Console.WriteLine(score);
- }
- Console.WriteLine("_____________");
- }
- public static void SelectionThree()
- {
- int low = 100;
- int high = 0;
- int sum = 0;
- foreach (int score in scores)
- {
- sum = sum + score;
- if (score > high)
- {
- high = score;
- }
- if (score < low)
- {
- low = score;
- }
- }
- Console.WriteLine("___Statistics___");
- Console.WriteLine("Low: " + low);
- Console.WriteLine("High: " + high);
- Console.WriteLine("Average: " + (sum / scores.Length));
- Console.WriteLine("_________________");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement