Question

In: Computer Science

#define _CRT_SECURE_NO_WARNINGS // Put your code below: #include <stdio.h> int main(void) { int day, hightemp[10], lowtemp[10],...

#define _CRT_SECURE_NO_WARNINGS

// Put your code below:

#include <stdio.h>


int main(void)
{
int day, hightemp[10], lowtemp[10], numbers, highesttemp, highestday, lowesttemp, lowestday, numbers2 = 0, hightotal = 0, lowtotal = 0, averageday = 0, numbers3;
double averagetemp;

printf("---=== IPC Temperature Calculator V2.0 ===---");

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


if (numbers < 3 || numbers > 10)

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

for (day = 1; day <= numbers; day++)
{
printf("Day %d - High: ", day);
scanf("%d", &hightemp[day - 1]);

printf("Day %d - Low: ", day);
scanf("%d", &lowtemp[day - 1]);

if(highesttemp <= highesttemp[day - 1])
{
highesttemp = highesttemp[day - 1];
highesttemp = day;
}

if (lowesttemp >= lowesttemp[day - 1])
{
lowesttemp = lowesttemp[day - 1];
lowesttemp = day;
}
}
printf("\nDay Hi Low\n");
for (day = 1; day <= numbers; day++)
{
printf("%d %d %d\n", day, hightemp[day - 1], lowtemp[day - 1]);

}

printf("\nThe highest temperature was %d, on day %d\n", highesttemp, highestday);

printf("The lowest temperature was %d, on day %d\n", lowesttemp, lowestday);

while (numbers2 == 0)
{
printf("\nEnter a number between 1 and 5 to see average temperature for the entered number of days, enter a negative number to exit: ", numbers);
scanf("%d", &numbers3);

if (numbers3 < 0)
{
numbers2 = 1;
}
else
{

while (numbers3 <= 0 || numbers3 > numbers)
{
printf("\nInvalid entry, please enter a number between 1 and %dm inclusive: ", numbers);
scanf("%d", &numbers3);
}
hightotal = 0;
lowtotal = 0;

for (averageday = 1; averageday <= numbers3; averageday++)
{
hightotal += hightemp[averageday - 1];
lowtotal += lowtemp[averageday - 1];
}

averagetemp = (double) (hightotal + lowtotal) / (numbers3 * 2);

printf("\nThe average temperature up to day %d is: %.2lf", numbers3, averagetemp);
}
}
printf("\nGoodbye!");
return 0;
}

/////////////////////////////////////////////////////////////////////////

why is it not working?

Solutions

Expert Solution

#define _CRT_SECURE_NO_WARNINGS

// Put your code below:

#include <stdio.h>

int main(void)
{
int day, hightemp[10], lowtemp[10], numbers, highesttemp, highestday, lowesttemp, lowestday, numbers2 = 0, hightotal = 0, lowtotal = 0, averageday = 0, numbers3;
double averagetemp;

printf("---=== IPC Temperature Calculator V2.0 ===---");

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

// validate numbers is between [3,10], re-prompt until valid
while (numbers < 3 || numbers > 10)
{
printf("\nInvalid entry, please enter a number between 3 and 10, inclusive: ");
scanf("%d", &numbers);
printf("\n");
}


for (day = 1; day <= numbers; day++)
{
printf("Day %d - High: ", day);
scanf("%d", &hightemp[day - 1]);

printf("Day %d - Low: ", day);
scanf("%d", &lowtemp[day - 1]);

// if this is first day or highesttemp <= hightemp for day, update highesttemp and highestday
if(day == 1 || highesttemp <= hightemp[day - 1]) // the array is hightemp not highesttemp
{
highesttemp = hightemp[day - 1];
highestday = day; // this should be highestday
}

// if this is first day or lowesttemp >= lowtemp for day, update lowesttemp and lowestday
if (day == 1 || lowesttemp >= lowtemp[day - 1]) // the array is lowtemp not lowesttemp
{
lowesttemp = lowtemp[day - 1];
lowestday = day; // this should be lowestday
}
}

printf("\nDay Hi Low\n");
for (day = 1; day <= numbers; day++)
{
printf("%d %d %d\n", day, hightemp[day - 1], lowtemp[day - 1]);
}

printf("\nThe highest temperature was %d, on day %d\n", highesttemp, highestday);

printf("The lowest temperature was %d, on day %d\n", lowesttemp, lowestday);

while (numbers2 == 0)
{
printf("\nEnter a number between 1 and %d to see average temperature for the entered number of days, enter a negative number to exit: ", numbers);
scanf("%d", &numbers3);

if (numbers3 < 0)
{
numbers2 = 1;
}

else
{

while (numbers3 <= 0 || numbers3 > numbers)
{
printf("\nInvalid entry, please enter a number between 1 and %dm inclusive: ", numbers);
scanf("%d", &numbers3);
}
hightotal = 0;
lowtotal = 0;

for (averageday = 1; averageday <= numbers3; averageday++)
{
hightotal += hightemp[averageday - 1];
lowtotal += lowtemp[averageday - 1];
}

averagetemp = (double) (hightotal + lowtotal) / (numbers3 * 2);

printf("\nThe average temperature up to day %d is: %.2lf", numbers3, averagetemp);
}
}

printf("\nGoodbye!");
return 0;
}

//end of program

Output:


Related Solutions

#include <stdio.h> #include <math.h> int fun(int); int main(void)    {     int i = 5, x...
#include <stdio.h> #include <math.h> int fun(int); int main(void)    {     int i = 5, x = 3;     i = fun(x);     printf("%d\n", i);     return 0; } int fun(int i) {      int res = 0;      res = pow (i , 3.0);      return ( res); }
example_thread.c #include <stdio.h> #include <stdlib.h> #include <pthread.h> int shared= 0; void race(void); int main(){     pthread_t...
example_thread.c #include <stdio.h> #include <stdlib.h> #include <pthread.h> int shared= 0; void race(void); int main(){     pthread_t player1, player2, player3;     pthread_create(&player1, NULL, (void *)race, NULL);     pthread_create(&player2, NULL, (void *)race, NULL);     pthread_create(&player3, NULL, (void *)race, NULL);     pthread_join(player1, NULL);     pthread_join(player2, NULL);     pthread_join(player3, NULL);     printf("Total Number = %d\n", shared);     return 0; } void race(void) {     long i,tmp;     for(i=1; i<=200000; i++) {         tmp = shared;         tmp = tmp + 1;         shared =...
#include <stdio.h> int main(void) { int input = -1; double average = 0.0;    /* Use...
#include <stdio.h> int main(void) { int input = -1; double average = 0.0;    /* Use this for your input */ scanf("%d", &input);    /* This is the only output you need */ printf("%.1lf", average); return 0; } Please write a C coding program (make it simple coding)  that find the average of sequence integer. when user enter integers, once at a time. Also, If the user enters 0 (zero), the code will calculates the average and then prints it, and...
#include <stdio.h> #include <stdlib.h> #include <time.h> void sort(int a[], int size); void printArray(int a[], int size);...
#include <stdio.h> #include <stdlib.h> #include <time.h> void sort(int a[], int size); void printArray(int a[], int size); int main(){ int arraySize, limit, count, srand(time(0)); print f("Enter the size of array\n"); scanf("%d", arraySize); int array[arraySize]; printf("Enter the upper limit\n"); scanf("%d", &limit); count = 0; while(count <= arraySize){ array[count] = (rand() % (limit + 1)); count++; } printArray(array, &arraySize); sort(array, arraySize); printArray(array, arraySize); Return 0; } void printArray(int a[], int size){ int i = 0; printf("Array: ["); while(i < size){ if(i != size...
#include <stdio.h> const int DECK_SIZE = 52; int deck[DECK_SIZE]; int main(void) { /* Populate the deck...
#include <stdio.h> const int DECK_SIZE = 52; int deck[DECK_SIZE]; int main(void) { /* Populate the deck */ for(int i = 0; i < DECK_SIZE; i++) { deck[i] = i + 1; }    /* Get the cut position as an integer input */    /* Verify that the input is valid */    /* Cut the deck */    /* Print the resulting deck with one element on each line */ return 0; } Write a program that "cuts" a...
CODE A #include<stdio.h> #include<math.h> #include<stdlib.h> #define PI 3.14159265358979323846 int main(){ int diameter; printf("Enter value of diameter...
CODE A #include<stdio.h> #include<math.h> #include<stdlib.h> #define PI 3.14159265358979323846 int main(){ int diameter; printf("Enter value of diameter between 8 to 60 inches: "); scanf("%d",&diameter); // if(diameter>60 || diameter<=8){ // printf("Error! invalid input"); // exit(0); // } // else{ // float radius = diameter/2; // float volume = (4/3)*PI*radius*radius*radius; // printf("%.2f",volume); // } //check through the while loop if it is valid or in valid while(diameter>60 || diameter<=8){ printf("Invalid input Enter again: "); scanf("%d",&diameter); }    //caluclate the volume of sphere float...
#include <stdio.h> int main(void) { float funds = 1.0, cost = 0.1; int candies = 0;...
#include <stdio.h> int main(void) { float funds = 1.0, cost = 0.1; int candies = 0; while(cost <= funds) { candies += 1; funds -= cost; cost += 0.1; } printf("%d candies with $%.2f left over.\n",candies,funds); return 0; } When you compile and run this code you get 3 candies with $0.40 left over. Without knowing how floating point numbers work in a computer, would this result be expected? Explain why or why not. Explain why this result, in fact,...
What is the output of the following C program? #include<stdio.h> int fac (int x); void main(...
What is the output of the following C program? #include<stdio.h> int fac (int x); void main( ) {                         for (int i=1; i<=2; i++)                                     printf("%d", fac(i)); } int fac(int x) {                         x = (x>1) ? x + fac(x-1) : 100);                         return x; }
Given a program as shown below: #include <stdio.h> void function1(void); void function2 (int, double x); void...
Given a program as shown below: #include <stdio.h> void function1(void); void function2 (int, double x); void main (void) { int m; double y; m=15; y=308.24; printf ("The value of m in main is m=%d\n\n",m); function1(); function2(m,y); printf ("The value of m is main still m = %d\n",m); } void function1(void) { printf("function1 is a void function that does not receive\n\\r values from main.\n\n"); } void function2(int n, double x) { int k,m; double z; k=2*n+2; m=5*n+37; z=4.0*x-58.4; printf ("function2 is...
Given a program as shown below: #include <stdio.h> void function1(void); void function2 (int, double x); void...
Given a program as shown below: #include <stdio.h> void function1(void); void function2 (int, double x); void main (void) { int m; double y; m=15; y=308.24; printf ("The value of m in main is m=%d\n\n",m); function1(); function2(m,y); printf ("The value of m is main still m = %d\n",m); } void function1(void) { printf("function1 is a void function that does not receive\n\\r values from main.\n\n"); } void function2(int n, double x) { int k,m; double z; k=2*n+2; m=5*n+37; z=4.0*x-58.4; printf ("function2 is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT