-
Arrays helps
Ok so my program is supposed to ask the use to enter 10 integer values , calculates the sum and average of all 10 integers and outputs the 10 numbers their sum and average .
I have this for the user input but it doesn't work can someone help me figure out what is wrong? I need to get it to display like this
You entered the following numbers:1,2,3,4,5,6,7,8,9,10
Code:
void getUserInput(int number[])
{
int num[10]= {1,2,3,4,5,6,7,8,9,10};
printf("%s%13s\n", "You entered the following numbers:");
for ( i=0; i <10;++i);{
printf("%7u%13d\n",num[i];
}
}
-
Those few lines are messy. Start by writing code that compiles. We'll gladly help you, but not if you don't put in some minimal effort.
-
Your task consists of 3 steps: input, processing output
Start with the first step. Use a for loop and scanf to read the numbers into your array.
To test that you read the input correctly output the array.
Once this is done move to the next step -> calculating the sum and average.
Good luck.
Here's a starting point.
Code:
#include <stdio.h>
#define NUMBER_COUNT 10
int main(void)
{
int numbers[ NUMBER_COUNT ] = {0};
/* 1. ask the use to enter 10 integer values */
/* 2. calculates the sum and average of all 10 integers */
/* 3. outputs the 10 numbers their sum and average . */
return 0;
}
-
In your printfs, the number of conversion specifications needs to match the number of parameters. Your for loop has an extra semicolon. The second printf is missing a right parenthesis. The "\n" in the second printf needs to go into a third one after the for loop or you will get a column of numbers instead of a row.