I just want to know how I could have a user input the data instead of having it fixed such as in { 56, 76, 2, 4, 5 }.
Im aware of the three codes here to input data but I dont know how to incorporate them in the code
ThanksCode:// Returns an int value from the console public static int GetInt(String prompt) { Console.Write(prompt); return int.Parse(Console.ReadLine()); } // Returns a double value from the console. public static double GetDouble(String prompt) { Console.Write(prompt); return double.Parse(Console.ReadLine()); } // Returns a char value from the console. public static char GetChar(String prompt) { Console.Write(prompt); return Console.ReadLine()[0]; } }
Code:using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication { class Program { static void Main(string[] args) { int[][] region = new int[3][]; // scores region[0] = new int[5] { 56, 76, 2, 4, 5 }; //region1 5 stores region[1] = new int[3] { 83, 44, 14 }; //region2 3 stores region[2] = new int[2] { 34, 78, }; //region3 2 stores double sum; // sum of the scores for each region for (int i = 0; i < region.Length; i++) { sum = 0; for (int j = 0; j < region[i].Length; j++) sum += region[i][j]; Console.Write ("The average for each region {0} is ", i); Console.WriteLine((sum / region[i].Length).ToString("F1")); } Console.ReadKey(); } } }


Reply With Quote


Bookmarks