Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Lab_4
  8. {
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14.  
  15. namespace Lab_4
  16. {
  17. class Program
  18. {
  19. static void Main(string[] args)
  20. {
  21.  
  22. // Constants
  23. const int min = 0;
  24. const int max = 50;
  25.  
  26. // Variables
  27. bool isValidNumber;
  28. int input;
  29. int[] carsEachDay = new int[7];
  30. int i = 0;
  31. bool done;
  32.  
  33. // Loops that validates if it is a number, and also puts it in order
  34. do
  35. {
  36. while (i < 7)
  37. {
  38. // prompt for a number
  39. Console.Write("Vehicles Sold On Day " + (i + 1) + ": ");
  40. // Tries to parse into an interger
  41. isValidNumber = int.TryParse(Console.ReadLine(), out input);
  42. // Validate if guess is a whole number
  43. if (!isValidNumber)
  44. Console.WriteLine("Error: input must be a whole number!");
  45. // Validate if guess is whitin range
  46. else if (input < min || input > max)
  47. Console.WriteLine("Error: Input must be between {0} and {1}.", min, max);
  48. else
  49. {
  50. carsEachDay[i] = input;
  51. ++i;
  52. }
  53. }
  54.  
  55. int sumCars = 0;
  56. int maxCars = carsEachDay[0];
  57. int maxCarsWhichDay = 1;
  58. int minCars = carsEachDay[0];
  59. int minCarsWhichDay = 1;
  60. for (int j = 0; j < 7; ++j)
  61. {
  62. Console.Clear();
  63.  
  64.  
  65. sumCars += carsEachDay[j];
  66. if (carsEachDay[j] > maxCars)
  67. {
  68. maxCars = carsEachDay[j];
  69. maxCarsWhichDay = j + 1;
  70. }
  71.  
  72. if (carsEachDay[j] < minCars)
  73. {
  74. minCars = carsEachDay[j];
  75. minCarsWhichDay = j + 1;
  76. }
  77. }
  78.  
  79. Console.WriteLine("Total cars sold: " + sumCars);
  80. Console.WriteLine("Average cars sold per day: " + (sumCars / 7));
  81. //Console.WriteLine("Most cars sold in a day: "+maxCars);
  82. Console.WriteLine("Most cars sold on day: " + maxCarsWhichDay);
  83. //Console.WriteLine("Least cars sold in a day: "+minCars);
  84. Console.WriteLine("Least cars sold on day: " + minCarsWhichDay);
  85.  
  86.  
  87. done = true;
  88. } while (!done);
  89.  
  90. // Press any key to exit
  91. Console.WriteLine("Press any key to exit...");
  92. Console.ReadKey();
  93. }
  94. }
  95.  
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement