1. ## Programing question

I am taking my first programming course. I am frustrated with my current assignment which is to creat a program that adds three numbers and finds their average. My problem is how to define "sum" and "average." This is, in part, my program:

int first_number
int second_number
int third_number

printf("Enter first_number;second_number, and third_number: ");
scanf("%d%d%d", &first_number, second_number, and third_number);

When I get to this part how do I "define" sum and average?

Thanks for your help. P.S. I am using the Borland Command Prompt programming software.

Mart00

2. Well, if you're simply entering integers, the sum can also be an integer. (Assuming you don't enter numbers so large that combine they won't fit in an integer.) If you want the average to use decimal places for some precision, then you'll want a floating point number.

If you plan on posting further here, you will need to go to the top of the forum and read the Announcements, which will instruct you on the proper way to post code as well as cover a few other forum guidelines.

Quzah.

3. you can define the sum to be an int type of variable, however, the average would have to be a float so as to include possibilty of decimal places, but you will have to typecast on the RHS during calculating average , as float.

something like

Code:
``` int num1,num2,num3;
float avg;
avg=((float)num1+num2+num3)/3;```
i suggest u pick up a good book on C and go through it.. this kind of example is very common in those books

the tutorial section of the site is worth a read too..try it out
- PING

4. Just thought you might like to know your scanf should be
Code:
`scanf("%d%d%d", &first_number, &second_number, &third_number);`
hobo

5. I tried to make things as readable as possible:

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

int main( void )
{
// _1, _2, _3 = input numbers from the user
// We use these numbers to find the average of them

int _1, _2, _3;

// t = Total of all of the 3 input numbers added together
// a = Average of the input numbers

int t;
int a;

// Ask the user for the numbers seperated by a space

printf( "Enter all three numbers seperated by a space: " );
scanf( "%d %d %d", &_1, &_2, &_3 );

// Calculate the total

t = _1 + _2 + _3;

// Get the average: TOTAL / TOTAL_NUMBERS

a = t / 3;

// Output average

printf( "%d\n", a );

// Exit success

return 0;
}```
Some example runs:
Code:
```Shiva:/home/kleid/Programming/Laboratory# ./a.out
Enter all three numbers seperated by a space: 3 5 2
3

Enter all three numbers seperated by a space: 1 5 10
6

Enter all three numbers seperated by a space: 10 30 80
37```

6. > int _1, _2, _3;
All symbols beginning with an underscore are reserved.

Why not use an array?
Then it's easy to extend to more than 3.

Not that you even need to store all the numbers just to compute an average.