Thread: Arrays helps

  1. #1
    Registered User
    Join Date
    Mar 2018
    Posts
    18

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

  2. #2
    Guest
    Guest
    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.

  3. #3
    Registered User
    Join Date
    Jun 2017
    Posts
    157
    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;
    }

  4. #4
    Registered User
    Join Date
    Apr 2017
    Location
    Quetzaltenango
    Posts
    82
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Somebody please helps me!
    By hchingwong in forum C Programming
    Replies: 3
    Last Post: 09-23-2010, 08:59 PM
  2. Helps with strings
    By 3wit in forum C Programming
    Replies: 3
    Last Post: 05-01-2008, 07:58 AM
  3. Arrays Dev-c++ (please helps)
    By lifeis2evil in forum C++ Programming
    Replies: 19
    Last Post: 12-12-2007, 12:39 PM
  4. CDC shape Helps
    By cfrost in forum C++ Programming
    Replies: 3
    Last Post: 05-13-2004, 05:49 AM
  5. Here's a problem, any one helps me?
    By NightWalker in forum C Programming
    Replies: 19
    Last Post: 06-10-2003, 09:19 AM

Tags for this Thread