Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Receiving Wrong Output

0 votes
asked Oct 6, 2018 by Qibs (270 points)

This is what the result needs to be:

https://imgur.com/a/2a1u3rb

But its outputting this:

https://imgur.com/a/9pz17vF

This is my code:

#define _CRT_SECURE_NO_WARNINGS

// Place your code below
#include <stdio.h>

int main(void)
{
 int i;
 int limit;
 int day[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
 int high[10], low[10];

 printf("---===IPC Temperature Analyzer V2.0===---\n");

 printf("Please enter the number of days between 3 and 10, inclusive: ");
 scanf("%d", &limit);
 while (limit <= 2 || limit >= 11) {
  printf("Invalid entry, please enter a number between 3 and 10,   inclusive: ");
  scanf("%d", &limit);
 }

 for (i = 0; i < limit; i++) {
  printf("Day %d - High: ", day[i]);
  scanf("%d", &high[i]);
  printf("Day %d - Low: ", day[i]);
  scanf("%d", &low[i]);
 }

 printf("\nDay Hi Low\n");
 for (i = 0; i < limit; i++) {
  printf("%d   %d    %d\n", day[i], high[i], low[i]);
 }

 int max = 0;
 int min = 0;

 for (i = 0; i < limit; 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]);

 int n;
 int avg = high[i] + low[i] / i;

 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");
 scanf("%d", &n);

 while (n > 4) {
  printf("Invalid entry, please enter a number between 1 and 4, inclusive: ");
  scanf("%d", &n);
 }

 while (n < 0) {
  printf("Goodbye!\n");
  exit(0);
 }

 for (i = 0; i < n; i++) {
  printf("The average temperature up to day %d is: %d", day[i], avg);
 }
 return 0;
}

1 Answer

0 votes
answered Oct 8, 2018 by anonymous

high[i] + low[i] / i;

should be 

(high[i] + low[i]) / i;

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...