Block of code works well accept for the fact

Assignment Help Business Management
Reference no: EM132139494

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

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

}

Reference no: EM132139494

Questions Cloud

Prevalence of hypertension : In the population below. What is the prevalence of hypertension among those who are not obese?
Compute the probability that both work : Compute the probability that both work. What is the probability at least one of the two televisions does not? work?
Assess outcomes against plans and standards : You will be required to research the cosmetic industry as a continuation of Project 1. Do not take the research lightly as you are required to do significant.
Compare the mission of the it professional organization : Considering their code of ethics, compare the mission of the following IT professional organization: ACM, IEEE, AITP, and PMI.
Block of code works well accept for the fact : 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
Program that displays the prime numbers : Need help with a program that displays the prime numbers in its command-line arguments, which are assumed to be integers. Example run of the program:
Database for in-class exercises and practice : We're starting a new project and need to know the names of our systems analysts and applications designers. Include last names labeled Employee and job titles l
Describe key religious practices for an individual follower : Describe key religious practices for an individual follower of Chinese popular religion in his or her daily life (e.g., arranging a marriage, funerals, etc.).
How did the lives of african americans change : How did the lives of women change over the course of the Nineteenth and Twentieth Centuries?

Reviews

Write a Review

Business Management Questions & Answers

  Caselet on michael porter’s value chain management

The assignment in management is a two part assignment dealing 1.Theory of function of management. 2. Operations and Controlling.

  Mountain man brewing company

Mountain Man Brewing, a family owned business where Chris Prangel, the son of the president joins. Due to increase in the preference for light beer drinkers, Chris Prangel wants to introduce light beer version in Mountain Man. An analysis into the la..

  Mountain man brewing company

Mountain Man Brewing, a family owned business where Chris Prangel, the son of the president joins. An analysis into the launch of Mountain Man Light over the present Mountain Man Lager.

  Analysis of the case using the doing ethics technique

Analysis of the case using the Doing Ethics Technique (DET). Analysis of the ethical issue(s) from the perspective of an ICT professional, using the ACS Code of  Conduct and properly relating clauses from the ACS Code of Conduct to the ethical issue.

  Affiliations and partnerships

Affiliations and partnerships are frequently used to reach a larger local audience? Which options stand to avail for the Hotel manager and what problems do these pose.

  Innovation-friendly regulations

What influence (if any) can organizations exercise to encourage ‘innovation-friendly' regulations?

  Effect of regional and corporate cultural issues

Present your findings as a group powerpoint with an audio file. In addition individually write up your own conclusions as to the effects of regional cultural issues on the corporate organisational culture of this multinational company as it conducts ..

  Structure of business plan

This assignment shows a structure of business plan. The task is to write a business plane about a Diet Shop.

  Identify the purposes of different types of organisations

Identify the purposes of different types of organisations.

  Entrepreneur case study for analysis

Entrepreneur Case Study for Analysis. Analyze Robin Wolaner's suitability to be an entrepreneur

  Forecasting and business analysis

This problem requires you to apply your cross-sectional analysis skills to a real cross-sectional data set with the goal of answering a specific research question.

  Educational instructional leadership

Prepare a major handout on the key principles of instructional leadership

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd