1. ## averaging numbers?

any idea how i would take a group of numbers, entered in the comand window, and make it spit out the average? I JUST started C so im very newb atm.

2. Originally Posted by rock4christ
any idea how i would take a group of numbers, entered in the comand window, and make it spit out the average?
Yes.

3. Originally Posted by kermit
Yes.
Could you help me whith it please?

Code:
```#include <stdio.h>

int main()                            /* Most important part of the program!
*/
{
int age;                          /* Need a variable... */

scanf( "%d", &age );                 /* The input is put in age */
if ( age < 100 ) {                  /* If the age is less than 100 */
printf ("You are pretty young!\n" ); /* Just to show you it works... */
}
else if ( age == 100 ) {            /* I use else just to show an example */
printf( "You are old\n" );
}
else {
printf( "You are really old\n" );     /* Executed if no other statement is
*/
}
return 0;
}```
why cant i enter an age in the command window with this? i hit enter and type a # then hit enter again and it closes.

5. Originally Posted by rock4christ
any idea how i would take a group of numbers, entered in the comand window, and make it spit out the average? I JUST started C so im very newb atm.
Hope this helps:

Code:
```input limit

sum=0
count=0

while (count<limit)
{
increment count
}

average = sum/count

print average```
Also look up this excellent link (slide 4 onwards explains the algorithm and program): http://www.csse.monash.edu.au/course...ect/lect10.ppt

6. i actually remembered another way i was shown, that works on mine:
at end of code
getch ();
return0;

but could you help on the averaging question?

7. Hey,
Enter your code within a while loop. You are getting only one age as input.
insert this while loop.

total = 0;
count = 0;
do
{

count ++;
total += age;
printf("Do you want to continue(y/n) :");
res = getc()
}while( res == 'y' )

average = total / count;

Jag

8. Originally Posted by rock4christ
but could you help on the averaging question?

9. getch() is non-standard. Meaning it may exist on your compiler but not on others. It's best for you to use a standard function like getchar() while you have one.

10. HWJR?

How would Jesus ROCK? HAHAHA You guys crack me up.

When you're not creeping me out that is.

Quzah.

11. What I don't get: how's the code copied and pasted from a tutorial related to your problems? What does a program that decides if a person is pretty yound, old or very old have to do with averaging input?

People like it if you show your efforts, not just any piece of code you can find.

12. they were 2 seperate questions, i just didnt want to make another thread.

13. The way to approach this, and certainly more taxing programs, is to think how would you get the average of a sequence of numbers? Add up all the numbers, and divide by the number of 'em, right? So,

Code:
```int NumOfNumbers = 0;
int Total = 0;

while ( You still wish to add numbers )
{
print - "do you want to add more numbers";

if ( yes )
{
NumOfNumbers++;
Get the number;
Number += The Gotten Number;
}
}
if ( NumOfNumbers isn't 0 )
{
average = Number/NumberOfNumbers;
}```
That's not real C, obviously, but it puts you in the thinking mode about how to accomplish the task. (as #7 said!!!)