Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static void Main(string[] args)
- {
- int n;
- do
- {
- Console.Write("Enter n: ");
- n = int.Parse(Console.ReadLine());
- } while (n > 31 || n <= 0);
- Console.WriteLine();
- double[] A, B, C;
- Console.WriteLine("For station A:\n");
- A = enterValues(n);
- Console.WriteLine("For station B:\n");
- B = enterValues(n);
- Console.WriteLine("For station C:\n");
- C = enterValues(n);
- Console.WriteLine();
- //a
- Console.Write("Average values for station A:\n{0:0.00} => ", findAvrgValueForMonth(A));
- Console.WriteLine();
- //b
- Console.Write("Average values for station B:\n{0:0.00} => ", findAvrgValueForMonth(B));
- Console.WriteLine();
- //c
- Console.Write("Average values for station C:\n{0:0.00} => ", findAvrgValueForMonth(C));
- Console.WriteLine();
- }
- static double findAvrgValueForMonth(double[] month)
- {
- double sum = 0;
- int counter = 0;
- for (int i = 0; i < month.Length; i++)
- {
- if (month[i] > 0)
- {
- sum += month[i];
- counter++;
- }
- }
- return sum/counter;
- }
- static double[] enterValues(int n)
- {
- double[] days = new double[n];
- for (int i = 0; i < n; i++)
- {
- enterValue:
- Console.Write("Enter liters for m2 for day {0}: ", i + 1);
- days[i] = double.Parse(Console.ReadLine());
- if (days[i] < 0)
- {
- Console.WriteLine("You can't enter negative value!");
- goto enterValue;
- }
- }
- return days;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment