Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.60 KB | None | 0 0
  1. public class Program
  2.     {
  3.         private static int[] scores;
  4.  
  5.         public static void Main(string[] args)
  6.         {
  7.             scores = new int[0];
  8.  
  9.             int selection = 0;
  10.             do
  11.             {
  12.                 selection = UserMenu();
  13.  
  14.                 if (selection == 1)
  15.                 {
  16.                     SelectionOne();
  17.                 }
  18.                 else if (selection == 2)
  19.                 {
  20.                     SelectionTwo();
  21.                 }
  22.                 else if (selection == 3)
  23.                 {
  24.                     SelectionThree();
  25.                 }
  26.             }
  27.             while (selection != 4);
  28.         }
  29.  
  30.         public static int UserMenu()
  31.         {
  32.             Console.WriteLine("________Menu________");
  33.             Console.WriteLine("1) enter scores");
  34.             Console.WriteLine("2) list scores");
  35.             Console.WriteLine("3) calculate statistics");
  36.             Console.WriteLine("4) exit");
  37.             Console.WriteLine("_____________________");
  38.             Console.WriteLine("Make a selection (1-4)");
  39.  
  40.             return Convert.ToInt32(Console.ReadLine());
  41.         }
  42.  
  43.         public static void SelectionOne()
  44.         {
  45.             Console.WriteLine("How many scores do you want to enter?");
  46.             int scoreCount = Convert.ToInt32(Console.ReadLine());
  47.             scores = new int[scoreCount];
  48.             for (int i = 0; i < scores.Length; i++)
  49.             {
  50.                 Console.WriteLine("Enter a score:");
  51.                 scores[i] = Convert.ToInt32(Console.ReadLine());
  52.             }
  53.         }
  54.  
  55.         public static void SelectionTwo()
  56.         {
  57.             Console.WriteLine("___Scores___");
  58.             foreach (int score in scores)
  59.             {
  60.                 Console.WriteLine(score);
  61.             }
  62.             Console.WriteLine("_____________");
  63.         }
  64.  
  65.         public static void SelectionThree()
  66.         {
  67.             int low = 100;
  68.             int high = 0;
  69.             int sum = 0;
  70.             foreach (int score in scores)
  71.             {
  72.                 sum = sum + score;
  73.                 if (score > high)
  74.                 {
  75.                     high = score;
  76.                 }
  77.                 if (score < low)
  78.                 {
  79.                     low = score;
  80.                 }
  81.  
  82.             }
  83.             Console.WriteLine("___Statistics___");
  84.             Console.WriteLine("Low: " + low);
  85.             Console.WriteLine("High: " + high);
  86.             Console.WriteLine("Average: " + (sum / scores.Length));
  87.             Console.WriteLine("_________________");
  88.         }
  89.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement