Having a little issue

0 votes
asked Oct 4, 2018 by Qibs

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;
}

3 Answers

0 votes
answered Oct 7, 2018 by Fady Serhan

they are about 3 errors in ur code...if this is still relevant reply here i'll give code the correction

commented Oct 7, 2018 by Qibs (270 points)
Yes it still is
commented Oct 7, 2018 by Qibs (270 points)
If you could help me with the issue I would appreciate it.
commented Oct 7, 2018 by Qibs (270 points)
The only issues left is the average is like 2.333333 and the other 2.5000000. Also, the average temp for the 2.333333 says day 4 but it needs to be 3 and the 2.5000000 day needs to be day 2. This might sound confusing.
commented Oct 7, 2018 by Fady Serhan (420 points)
check now: https://onlinegdb.com/HJm289L5X

just put "n" instead of "day[i]" in the printf
commented Oct 7, 2018 by Fady Serhan (420 points)
and if you want only 2 numbers after the point heres the fix: https://onlinegdb.com/HyjMccU5m
0 votes
answered Oct 7, 2018 by Fady Serhan

Ok, I fixed your code, I put some comments in the code so you can understand the errors, you can see difference also by comparing to ur original code.

heres the link: https://www.onlinegdb.com/HkiDWcUqX

if there's still problem reply to me, Good luck.

commented Oct 7, 2018 by Qibs (270 points)
Still having a issue...I cant seem to get the correct average it needs to be 2.50 and 2.75....
commented Oct 7, 2018 by Qibs (270 points)
THIS IS MY NEW CODE CAN U JUST HELP ME ADD IN HIGHEST AND LOWEST TEMPTURE

#define _CRT_SECURE_NO_WARNINGS



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

int main(void)
{

    int i, NUMS;
    int day = { 1-10 };
    int totalHigh = 0;
    int totalLow = 0;
    int high[10];
    int low[10];
    double average;


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

    printf("Please enter the number of days, between 3 and 10, inclusive: ");
    scanf("%d", &NUMS);
    printf("\n");

    while (NUMS < 3 || NUMS > 10)
    {
        printf("Invalid entry, please enter a number between 3 and 10, inclusive: ");
        scanf("%d", &NUMS);
        printf("\n");
    }

    for (i = 0; i < NUMS; i++)
    {
        printf("Day %d - High: ", i + 1);
        scanf("%d", &high[i]);

        printf("Day %d - Low: ", i + 1);
        scanf("%d", &low[i]);

        while (high[i] > 40 || high[i] < -40 || low[i] > 40 || low[i] < -40 || high[i] < low[i])
        {
            printf("Incorrect values, temperatures must be in the range -40 to 40, high must be greater than low.\n");
            printf("\n");
            printf("Day %d - High: ", i + 1);
            scanf("%d", &high[i]);

            printf("Day %d - Low: ", i + 1);
            scanf("%d", &low[i]);
        }

    }

    printf("\n");
    printf("Day  Hi  Low\n");
    printf("\n");

    for (i = 0; i < NUMS; i++)
    {
        printf("%d    %d    %d\n", i + 1, high[i], low[i]);
    }

    printf("\n");
    printf("Enter a number between 1 and %d to see the average temperature for the entered number of days, enter a negative number to exit: ", NUMS);
    scanf("%d", &day);

    while (day == 0 || day > NUMS)
    {
        printf("\n");
        printf("Invalid entry, please enter a number between 1 and %d, inclusive: ", NUMS);
        scanf("%d", &day);
    }

    while (day <= NUMS && day > 0)
    {

        for (i = 0; i < day; i++)
        {
            totalHigh += high[i];
            totalLow += low[i];
            average = (double)(totalHigh + totalLow) / (day * 2);
        }

        printf("\n");
        printf("The average temperature up to day %d is: %.2lf\n", day, average);
        printf("\n");
        printf("Enter a number between 1 and %d to see the average temperature for the entered number of days, enter a negative number to exit: ", NUMS);
        scanf("%d", &day);
        totalHigh = 0; totalLow = 0; average = 0;
    }

    if (day == -1)
    printf("\nGoodbye!\n");

    return 0;
}
0 votes
answered Oct 7, 2018 by Fady Serhan (420 points)

Ok listen I think this final code works great link:-

https://onlinegdb.com/SJMyutDqX

I tested the average and it's ok....

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.
...