CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2002
    Posts
    2

    in serious need of help

    array creation...

    simple attempt to impress a lady backfires. she asked if i could do it, course i said,but then promptly forgot to do it, now she needs it and im buggered!!! as i dont know how to do this in c++, but hey she needn't know eh?

    ok, need to process a set of numerical values stored in an array.these values will be entered by user at run time. can enter any amount up to 50.
    must calculate the following
    a)count of numbers input
    b)max and min of input values
    c)range
    d)mean value
    e)median

    just something quick and simple that works... as i cannot do it for the life of me...

    cheers i'll let u know how i get on


  2. #2
    Join Date
    Apr 2002
    Posts
    11

    Re: in serious need of help

    sample simple code:


    ...

    #define MAX_SIZE 50 // maximum array size

    // getting array size from user
    int GetArraySize();
    // function gets array from input
    void GetArray(float *array, int size);
    // getting range
    float Range(float *array, int size);
    // getting max value
    float Max(float *array, int size);
    ...
    // output program results
    void Report(float *array, int size);

    void main()
    {
    float array[MAX_SIZE];

    int size = GetArraySize();
    GetArray(array, size);
    Report(array, size);
    }

    int GetArraySize()
    {
    int size = 0;
    while(size < 0 || size > MAX_SIZE)
    {
    printf("Input array size: ");
    scanf("%d", &size);
    if(size > 0 && size < MAX_SIZE) break;
    printf("\nWrong size.\n");
    }

    }

    void GetArray(float *array, int size)
    {
    printf("\nInput array: ");
    for(int i = 0; i < size; i++)
    scanf("%f", array + i);
    }

    void Report(float *array, int size)
    {
    float range = Range(float *array, int size);
    float max = Max(float *array, int size);
    ...
    printf("Range: %f", range);
    printf("Max: %f", max);
    ...
    }

    float Range(float *array, int size)
    {
    ...
    }

    ...







  3. #3
    Join Date
    Apr 2002
    Posts
    2

    Re: in serious need of help

    cheers mate, lets hope she can fill in the blanks


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured