Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Business Management Expert

The following block of code works well accept for the fact that when it attempts to calculate the average temperature in a given amount of days, it does some math wrong. I put in a printf statement to isolate the problem and it seems to be adding wrong. Example; when I put in 6 -2 8 and -1, it adds them up and gets 13.50. I think its a casting problem but whenever I try to solve that I make it worse. How do I fix this?

#include

#define SIZE 10

int main() {

int averageDays = 0;

double average = 0.0;

int high[SIZE];

int low[SIZE];

int days;

int counter;

int hottestTemp = -40;

int lowestTemp = 40;

int highestDay, lowestDay;

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

printf("Please enter the number of days, between 3 and 10, inclusive: ");

scanf("%d", &days);

while (days < 3 || days > 10) {

printf("nInvalid entry, please enter a number between 3 and 10, inclusive: ");

scanf("%d", &days);

}

printf("n"); // this is just for spacing

for (counter = 0; counter < days; counter++) {

printf("Day %d - High: ", counter + 1);

scanf("%d", &high[counter]);

printf("Day %d - Low: ", counter + 1);

scanf("%d", &low[counter]);

}

printf("nDay Hi Low");

for (counter = 0; counter < days; counter++) {

printf("n%d  %d  %d", counter + 1, high[counter], low[counter]);

}

printf("nn");

for (counter = 0; counter < days; counter++) {

if (hottestTemp < high[counter]) {

hottestTemp = high[counter];

highestDay = counter + 1;

}

if (lowestTemp > low[counter]) {

lowestTemp = low[counter];

lowestDay = counter + 1;

}

}

printf("The highest temperature was: %d, on day %dn", hottestTemp, highestDay);

printf("The lowest temperature was: %d, on day %dn", lowestTemp, lowestDay);

while (averageDays > -1) {

printf("nEnter a Number Between 1 and %d to see the average temperature for the entered number of days, enter a negative number to exit: ", days);

scanf("%d", &averageDays);

while (averageDays > days) {

printf("nInvalid entry, please enter a number between 1 and %d, inclusive: ", days);

scanf("%d", &averageDays);

}

for (counter = 0; counter < averageDays; counter++) {

average = average + (double)high[counter] + (double)low[counter];

}

printf("%.2lf, %d", average, averageDays);

average = average / (averageDays * 2);

if (averageDays > 0) {

printf("nThe average temperature up to day %d is: %.2lfn", averageDays, average);

}

else

{

printf("nGoodbye!n");

}

}

return 0;

}

Business Management, Management Studies

  • Category:- Business Management
  • Reference No.:- M93126959
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Business Management

Explain what strategies used by breadtalk and analyse and

Explain what strategies used by BreadTalk and analyse and evaluate its strategic performance (details).

Are there two possibilities for starbucks to increase their

Are there two possibilities for Starbucks to increase their brand loyalty for its product? And how can those possibilities help Starbucks to maintain their market share?

How to create effective ethical polices in the work place

How to create effective ethical polices in the work place? What is the impact of ethical assessment in the work place? How to classify Alcoa's ethical work climate?

You begin work at the happy-go-lucky corporation on

You begin work at the Happy-Go-Lucky Corporation on Halloween. On your second day at work, you wear a political button on your coat, supporting your choice for US senator in the upcoming election. Your boss, who is of a ...

The authors distinguish between controllable and

The authors distinguish between controllable and uncontrollable factors that influence the demand for a product. One of the controllable factors on their list is advertising --- do you agree with this classification? Com ...

Explain and compare the advantages of servlets java desktop

Explain and compare the advantages of Servlets, Java Desktop Applications and Web Start.

In order to provide career development opportunities to

In order to provide career development opportunities to employees, many organizations have developed their own universities or training programs. What are the advantages and disadvantages in doing this?

Differentiate between strategy and operational

Differentiate between strategy and operational effectiveness. Why are they commonly confused?

Question from sam b to elephant logistics amp sc

Question: FROM: Sam B. TO: Elephant Logistics & SC Consultants RE: Feasibility Study of Specialty European Beverage Line As you know, my European vacation offered me the opportunity to experience many different beverages ...

What is the relation between mrs marginal rate of

What is the relation between MRS (Marginal Rate of Substitution) and MRT (Marginal Rate of Transformation) at autarky equilibrium? Are they equal? Why?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As