Hi all, so I'm stuck on a certain part of a program for my C class. Okay the program is supposed to query a user for a set number of entries for temperatures which is 26. It is supposed to take those temperatures and calculate the avg. at the end. Here's the part I'm lost on; There's 3 ranges for these temps to be specified; hot, cold, and pleasant. Besides returning the avg. number of all the temps. entered it also has to return how many hot, cold, and pleasant days were entered. I'm using a for loop and if statements to to gather the 26 entries and calculate the avg. But I'm lost on how to sum up how many hot, pleasant, and cold days and return the printf statement saying so. Should I use an array to do this? Thanks for any insight.
bwjones
0
Junior Poster in Training
Recommended Answers
Jump to Post>Should I use an array to do this?
Sounds good to me. You need to store the count somewhere, and an array keeps the three counts neatly organized under one object.
Jump to PostI don't see what the problem is. It's not hard to keep a count of some metric in your loop and then print the count later. Maybe you should post your code so I don't have to guess what you're doing wrong.
Jump to PostPay close attention to the names of the functions that you (a) declare, (b) call, and (c) define. Short of this trifecta, you're asking for linker errors.
Jump to Postvoid calculate_and_print(int n); is not the same than void calculate(int n)
double get_value(void); is not foundprintf("The average temperature is %lf\n\n",n, average); /* remove the n and the l */
All 14 Replies
Narue
5,707
Bad Cop
Team Colleague
bwjones
0
Junior Poster in Training
Narue
5,707
Bad Cop
Team Colleague
bwjones
0
Junior Poster in Training
bwjones
0
Junior Poster in Training
Dave Sinkula
2,398
long time no c
Team Colleague
Aia
1,977
Nearly a Posting Maven
bwjones
0
Junior Poster in Training
Dave Sinkula
2,398
long time no c
Team Colleague
bwjones
0
Junior Poster in Training
Drake
-1
Newbie Poster
bwjones
0
Junior Poster in Training
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
bwjones
0
Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.