C programing help?

lankygiant16

Baseband Member
Messages
63
So i have this program i need to have done tomorrow....i have it mostly done...but the last two things. I need to figure out how to get my average to work right. I know it seems simple...but i cant get it.....my average always comes out to some number......if you copy and paste my code...you will see. It has to do with my total and/or my average section.....lol if that makes sence....heres the code.


#include <stdio.h>

int main (void)
{
int count, i;
double fahr=0, total=0, avg;

printf( "Enter a number between 1 and 25:\n");
scanf("%i", &count);

while ((count < 1) || (count > 25))
{
printf( "The number entered is out of range.\n");
scanf( "%i", &count);
}
printf( "The number is in range");


for(i=1; i <= count; i++)
{
printf( "\nEnter in a temperature for fahrenheit:");
scanf( "%lf", &fahr);

while(fahr < -125.0 || fahr > 125.0)
{
printf( "The number entered is out of range, please re-enter:");
scanf( "%.1lf", &fahr);
}
}
total= total + fahr;
avg= total / fahr;

printf( "\nThe average of the numbers entered is %.1lf.\n", avg);

return 0;
}


after the while statement is where i need the work done (or so i think)....any help would be GRAND!!! thanks a bunch guys!
 
ok new update....i got that last part...finally....but now im having the same problem with another problem.......



..........................
while(fahr < -125.0 || fahr > 125.0)
{
printf( "The number entered is out of range, please re-enter:");
scanf( "%.1lf", &fahr);
}

total = total + fahr;

}
avg_fahr = total / count;

avg_cels= (avg_fahr - 32) * (5/9);


printf( "\n Jim Hayes - Assignment2\n");
printf( "\n Fahr Cels\n");
printf( " ======= =======\n");


printf( " Average %13.1lf %13.1lf\n", avg_fahr, avg_cels);

return 0;
}

now the avg_cels is coming out to 0.0......WTF?!?!?!
 
Back
Top Bottom