Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Name: vinod ragoonauth
- // Student Number: 115197170
- // Email: vragoonauth@mysenecac.ca
- // Section: SYY
- // Workshop: 4
- #define _CRT_SECURE_NO_WARNINGS
- // Place your code below
- #include <stdio.h>
- int main(void)
- {
- int i; //initializes the variable i
- int numDays; //variable to hold user input for amount of days
- int day[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; //array for storing and printing days for each day
- int high[10], low[10]; //stores high and low values in specified arrays
- int max = 0; //stores max
- int min = 0; //stores min
- int tempDays;
- float avgSum = 0.0;
- printf("---=== IPC Temperature Calculator V2.0 ===---\n"); //prints title
- printf("Please enter the number of days, between 3 and 10, inclusive: "); //prompt user to input number of days
- scanf("%d", &numDays); // stores user input in variable numDays
- while (numDays < 3 || numDays > 10) //condition that will run body is numDays is less than 3 or greater than 10
- {
- printf("\nInvalid entry, please enter a number between 3 and 10, inclusive: "); //prompt the user to input the correct info again
- scanf("%d", &numDays); //stores info in numDays
- }
- printf("\n"); //prints space
- for (i = 0; i < numDays; i++) //loops for the amount of days entered by user
- {
- printf("Day %d - High: ", day[i]); //prints respected day and prompts user to input high value
- scanf("%d", &high[i]); //stores high value in a array
- printf("Day %d - Low: ", day[i]); //prints respected day and prompts user to input low value
- scanf("%d", &low[i]); // store low value in a array
- }
- printf("\nDay Hi Low\n"); //prints labels
- for (i = 0; i < numDays; i++) //runs for amount of days entered
- {
- printf("%d %d %d\n", day[i], high[i], low[i]); //prints the day, high val, and low val for each loop
- }
- for (i = 0; i < numDays; i++) {
- if (high[max] < high[i])
- max = i;
- if (low[min] > low[i])
- min = i;
- }
- printf("\nHighest temperature was: %d on day %d", high[max], day[max]);
- printf("\nLowest temperature was: %d on day %d ", low[min], day[min]);
- 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");
- scanf("%d", &tempDays);
- while (tempDays > 4) {
- printf("Invalid entry, please enter a number between 1 and 4, inclusive: ");
- scanf("%d", &tempDays);
- }
- while (tempDays > 0) {
- for (i = 0; i < tempDays; i++) {
- float avgOfDay = (high[i] + low[i]) / 2.0;
- avgSum += avgOfDay;
- }
- float overallAvg = avgSum / tempDays;
- printf("The average temperature up to day %d is: %.2f", day[tempDays - 1], overallAvg);
- 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");
- scanf("%d", &tempDays);
- }
- printf("Goodbye!\n");
- exit(0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement