# Thread: HW Help - Average & Total of six integers

1. ## HW Help - Average & Total of six integers

I am trying to complete this assignment, but I'm stuck, can anybody help me fix my code?

"Write a program that prompts the user for an integer number from the keyboard, and store it in a variable num. After each number is typed in, add num to a total.
Do this six times, each time adding num to a total. (Be sure to reuse the same variable named num for each of the six numbers entered.) When all six numbers have been entered from the keyboard, calculate an average.
Display the total and average calculated. "

Here is what I have so far:

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

int main()
{
int num, total1, total2, total3, total4, total5, total6, avg;

printf("Enter first number:");
scanf("%2d",&num);

int total1 = 0 + num

printf("Enter second number:");
scanf("%2d",&num);

int total2 = total1 + num

printf("Enter third number:");
scanf("%2d",&num);

int total3 = total2 + num

printf("Enter fourth number:");
scanf("%2d",&num);

int total4 = total3 + num

printf("Enter fifth number:");
scanf("%2d",&num);

int total5 = total4 + num

printf("Enter sixth number:");
scanf("%2d",&num);

int total6 = total5 + num

avg = total6 / 6.0;

printf("\nTotal: %d", total6);
printf("\nAverage: %f", avg);

return 0;
}``` 2. You treat avg as a float variable (which is correct), but you have declare it as int one (which is not ok). Declare it as a double and report back. 3. ## Code:
```    int num=0;
int avg,input;

printf("Enter first number:");
scanf("%d",&input);
num+=input;
/*
*
*
*
**/
avg=num/6;
printf("\nTotal: %d",num);
printf("\nAverage: %d",avg);

return (0);
}```
/*You can also do this using a loop to save time. Try it.*/ Popular pages Recent additions 