Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 10-09-2006, 12:09 AM   #1
Baseband Member
 
lankygiant16's Avatar
 
Join Date: Aug 2006
Posts: 63
Default C programing help?

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!
__________________

lankygiant16 is offline   Reply With Quote
Old 10-09-2006, 12:58 AM   #2
Baseband Member
 
lankygiant16's Avatar
 
Join Date: Aug 2006
Posts: 63
Default Re: C programing help?

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?!?!?!
__________________

lankygiant16 is offline   Reply With Quote
Old 10-14-2006, 01:38 PM   #3
Beta Member
 
Join Date: Oct 2006
Posts: 1
Default Re: C programing help?

integer divison... try changing 5/9 to 5.0 over 9.0 its a common problem in java it might help
d34thd34l3r is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 10:29 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0