Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
578
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.87 KB | None | 0 0
  1. // Name: vinod ragoonauth
  2. // Student Number: 115197170
  3. // Email: vragoonauth@mysenecac.ca
  4. // Section: SYY
  5. // Workshop: 4
  6.  
  7. #define _CRT_SECURE_NO_WARNINGS
  8.  
  9. // Place your code below
  10.  
  11. #include <stdio.h>
  12.  
  13. int main(void)
  14. {
  15.     int i; //initializes the variable i
  16.     int numDays; //variable to hold user input for amount of days
  17.     int day[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; //array for storing and printing days for each day
  18.     int high[10], low[10]; //stores high and low values in specified arrays
  19.     int max = 0; //stores max
  20.     int min = 0; //stores min
  21.     int tempDays;
  22.     float avgSum = 0.0;
  23.  
  24.  
  25.     printf("---=== IPC Temperature Calculator V2.0 ===---\n"); //prints title
  26.  
  27.     printf("Please enter the number of days, between 3 and 10, inclusive: "); //prompt user to input number of days
  28.     scanf("%d", &numDays); // stores user input in variable numDays
  29.  
  30.  
  31.     while (numDays < 3 || numDays > 10) //condition that will run body is numDays is less than 3 or greater than 10
  32.     {
  33.         printf("\nInvalid entry, please enter a number between 3 and 10, inclusive: "); //prompt the user to input the correct info again
  34.         scanf("%d", &numDays); //stores info in numDays
  35.  
  36.     }
  37.  
  38.     printf("\n"); //prints space
  39.  
  40.     for (i = 0; i < numDays; i++) //loops for the amount of days entered by user
  41.     {
  42.         printf("Day %d - High: ", day[i]); //prints respected day and prompts user to input high value
  43.         scanf("%d", &high[i]); //stores high value in a array
  44.  
  45.         printf("Day %d - Low: ", day[i]); //prints respected day and prompts user to input low value
  46.         scanf("%d", &low[i]); // store low value in a array
  47.     }
  48.  
  49.     printf("\nDay  Hi  Low\n"); //prints labels
  50.  
  51.     for (i = 0; i < numDays; i++) //runs for amount of days entered
  52.     {
  53.         printf("%d    %d    %d\n", day[i], high[i], low[i]); //prints the day, high val, and low val for each loop
  54.     }
  55.  
  56.     for (i = 0; i < numDays; i++) {
  57.         if (high[max] < high[i])
  58.             max = i;
  59.  
  60.         if (low[min] > low[i])
  61.             min = i;
  62.     }
  63.  
  64.     printf("\nHighest temperature was: %d on day %d", high[max], day[max]);
  65.     printf("\nLowest temperature was: %d on day %d ", low[min], day[min]);
  66.  
  67.     printf("\nEnter a number between 1 and 4 to see the average temperature for the entered number of days, enter a negative number to exit:\n");
  68.     scanf("%d", &tempDays);
  69.  
  70.     while (tempDays > 4) {
  71.         printf("Invalid entry, please enter a number between 1 and 4, inclusive: ");
  72.         scanf("%d", &tempDays);
  73.     }
  74.  
  75.     while (tempDays > 0) {
  76.        
  77.         for (i = 0; i < tempDays; i++) {
  78.             float avgOfDay = (high[i] + low[i]) / 2.0;
  79.             avgSum += avgOfDay;
  80.         }
  81.  
  82.         float overallAvg = avgSum / tempDays;
  83.         printf("The average temperature up to day %d is: %.2f", day[tempDays - 1], overallAvg);
  84.  
  85.         printf("\nEnter a number between 1 and 4 to see the average temperature for the entered number of days, enter a negative number to exit:\n");
  86.         scanf("%d", &tempDays);
  87.  
  88.     }
  89.  
  90.     printf("Goodbye!\n");
  91.     exit(0);
  92.  
  93.     return 0;
  94.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement