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.
Need help with C code:?
You could use an array, but since you only need 3 values how about variables named hot, cold, and pleasant all initialized to zero. Every time you read a value, use if's (or 'select' maybe if you've covered that yet) to determine which one it is and increment the prper variable:
pseudocode:
if input %26lt; 50
cold++
else if input %26lt; 85
pleasant++
else
hot++
Reply:ok so you have a loop that gets the data
next :
3 vairbles, hot cold and pleasant
have a if statement check to see what range the number is in
If (data %26lt; 10 %26amp;%26amp; data %26gt;5) hot++;
then add it to your total
then count++
at the end ave = (float) total / count;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment