Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Lab_4
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Lab_4
- {
- class Program
- {
- static void Main(string[] args)
- {
- // Constants
- const int min = 0;
- const int max = 50;
- // Variables
- bool isValidNumber;
- int input;
- int[] carsEachDay = new int[7];
- int i = 0;
- bool done;
- // Loops that validates if it is a number, and also puts it in order
- do
- {
- while (i < 7)
- {
- // prompt for a number
- Console.Write("Vehicles Sold On Day " + (i + 1) + ": ");
- // Tries to parse into an interger
- isValidNumber = int.TryParse(Console.ReadLine(), out input);
- // Validate if guess is a whole number
- if (!isValidNumber)
- Console.WriteLine("Error: input must be a whole number!");
- // Validate if guess is whitin range
- else if (input < min || input > max)
- Console.WriteLine("Error: Input must be between {0} and {1}.", min, max);
- else
- {
- carsEachDay[i] = input;
- ++i;
- }
- }
- int sumCars = 0;
- int maxCars = carsEachDay[0];
- int maxCarsWhichDay = 1;
- int minCars = carsEachDay[0];
- int minCarsWhichDay = 1;
- for (int j = 0; j < 7; ++j)
- {
- Console.Clear();
- sumCars += carsEachDay[j];
- if (carsEachDay[j] > maxCars)
- {
- maxCars = carsEachDay[j];
- maxCarsWhichDay = j + 1;
- }
- if (carsEachDay[j] < minCars)
- {
- minCars = carsEachDay[j];
- minCarsWhichDay = j + 1;
- }
- }
- Console.WriteLine("Total cars sold: " + sumCars);
- Console.WriteLine("Average cars sold per day: " + (sumCars / 7));
- //Console.WriteLine("Most cars sold in a day: "+maxCars);
- Console.WriteLine("Most cars sold on day: " + maxCarsWhichDay);
- //Console.WriteLine("Least cars sold in a day: "+minCars);
- Console.WriteLine("Least cars sold on day: " + minCarsWhichDay);
- done = true;
- } while (!done);
- // Press any key to exit
- Console.WriteLine("Press any key to exit...");
- Console.ReadKey();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement