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;
}