Thread: Sending Values and Scanning an Array

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    23

    Sending Values and Scanning an Array

    I don't know why this isn't working PLZ need help.

    Assignment:
    Write a program which prompts the user to enter the number of values to process
    (a maximum of 100). Next prompt, and allow the user to enter each of the
    values. Store these values in an array. Print the largest value, the smallest
    value, and the average (to 2 decimal places) of the values in the array. You must
    use functions for each of these tasks. The GetValues() function is the only
    function that may change the array.

    The prototypes for the functions must be:
    void GetValues(int x[], int *pN);
    int FindBig(int x[], int n);
    int FindSml(int x[], int n);
    float FindAvg(int x[], int n);

    GetValues should put values in both the x[] array and at *pN
    FindBig should return the largest integer in the first n elements of x[]
    FindSml should return the smallest integer in the first n elements of x[]
    FindAvg should return the average of the first n elements of x[]

    A sample run is shown below (user input underlined). Note that user is prompted
    for value 1, 2, 3, ... as opposed to 0, 1, 2, ... .


    Enter number of integer values: 5
    Enter value 1: 20
    Enter value 2: -15
    Enter value 3: 90
    Enter value 4: 2
    Enter value 5: 30
    The largest value is: 90
    The smallest value is: -15
    The average value is: 25.40
    CODE

    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>

    void GetValues(int x[], int *pN);
    int FindBig(int x[], int n);
    int FindSml(int x[], int n);
    float FindAvg(int x[], int n);

    void main()
    {

    int a[100], myBig, mySml, n;
    float myAvg;
    GetValues(a,&n);
    myBig=FindBig(a,n);
    mySml=FindSml(a,n);
    myAvg=FindAvg(a,n);
    printf("The largest value is: %d\n",myBig);
    printf("The smallest value is: %d\n",mySml);
    printf("The average value is: %.2f\n",myAvg);

    void GetValues(int x[], int *pN);
    printf("Enter number of integer values: ");
    scanf("%d", &a[100]);

    for(a[100]=0; a[100] <= 100; a[100]++)
    {
    printf("Enter Value %d: ");
    scanf("%d", &n, &myBig, &mySml);
    int FindBig(int x[], int n);
    int FindSml(int x[], int n);
    {
    float FindAvg(int x[], int n);
    myAvg = myAvg/a[100];
    }
    }
    }
    Last edited by xxxixpats; 11-05-2010 at 09:42 PM.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    What problems are you having?

    Does the code compile?

    If not, please post the entire error message.

    Jim

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    23
    Here is all the Error Messages I am getting
    Error 5 error LNK1120: 4 unresolved externals

    Error 1 error LNK2019: unresolved external symbol "float __cdecl FindAvg(int * const,int)" (?FindAvg@@YAMQAHH@Z) referenced in function _main

    Error 2 error LNK2019: unresolved external symbol "int __cdecl FindSml(int * const,int)" (?FindSml@@YAHQAHH@Z) referenced in function _main


    Error 3 error LNK2019: unresolved external symbol "int __cdecl FindBig(int * const,int)" (?FindBig@@YAHQAHH@Z) referenced in function _main


    Error 4 error LNK2019: unresolved external symbol "void __cdecl GetValues(int * const,int *)" (?GetValues@@YAXQAHPAH@Z) referenced in function _main

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Have you written the code for these functions?

    I don't see them anywhere in the code you supplied.

    Jim

  5. #5
    Registered User
    Join Date
    Nov 2010
    Posts
    23
    well this is my first ever program class, so im kind of confused with what im supposed to write...

    Arrays confuse me, so i don't really know what im supposed to do.

    I supplied the actual assignment, which is located on the top of the post right above the code

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    You do this:

    Write a program which prompts the user to enter the number of values to process
    (a maximum of 100). Next prompt, and allow the user to enter each of the
    values. Store these values in an array
    in this function:

    Code:
    void GetValues(int x[], int *pN);


    Code:
    void GetValues(int x[], int *pN)
    {
       // Get user input for number of values here. 
    
       // insure it is less than 100 
    
       //(Store it in *pN)
    
       // Now get user input for the values. Store them in the array x[]
    
       // GetValues should put values in both the x[] array and at *pN
    
    }
    You instructions tell you what each function should look like, what it should do.

    You need to write the functions to do what the instructions say.

    Give it a try. When and if you run into trouble come on back.

    Tell us your specific problem.

    Post the modified code with the entire error messages.


    Jim

  7. #7
    Registered User
    Join Date
    Nov 2010
    Posts
    23
    okay TY

  8. #8
    Registered User gaurav9991's Avatar
    Join Date
    Oct 2010
    Location
    Pune, Maharashtra, India
    Posts
    69
    don't use void main()

    Cprogramming.com FAQ > main() / void main() / int main() / int main(void) / int main(int argc, char *argv[])

    here is the framework one should use for simple programs

    Code:
    function_1(parameters)   // function definition
    {
          // function body
    }
    
    function_2(parameters)     // function definition
    {
          // function body
    }
    
    
    int main()
    {
           //variable declarations
    
           function_1(parameters);     // function call
    
           function_2(parameters);      // function call
    
           return 0;  
    }
    if you write function definition before main(), no need for function declaration as you did. but for lengthy programs having no. of functions, writing function declaration gives idea about functions used in code.

    try it and post

    thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making A Program That Outputs Array Values
    By xxxixpats in forum C Programming
    Replies: 3
    Last Post: 11-04-2010, 05:21 PM
  2. Making A Program That Outputs Array Values
    By xxxixpats in forum C Programming
    Replies: 1
    Last Post: 11-03-2010, 10:08 AM
  3. Reading Picture file into 2dimensional data array?
    By DiscoStu9 in forum C Programming
    Replies: 10
    Last Post: 08-25-2009, 06:03 PM
  4. scanning and writing data to a file simultaneously
    By Gades in forum C Programming
    Replies: 1
    Last Post: 11-14-2001, 07:51 AM