Thread: what's wrong with my newbie program??

  1. #1
    insoolated
    Guest

    Unhappy what's wrong with my newbie program??

    This is a homework problem
    I tried it out... but I get errors and I have no idea what they mean... would someone help me a little please?

    ok.. i think writing out the problem will help whoever helps to get a better idea --->
    Write a complete program that does the following:
    The main() should ask the user for a number and store it in an integer variable named input. The main() should pass by value the integer to the function "int fxn1 (int x, int array[])"
    fxn1 should ask the user how many muiltiples to calculate and store the users response in an int varialbe named num. fxn1 should then store the first num multiplies of x in array.
    NOTE: store the first multiple in position 0, the second multiple in postion 1, and so on. The main should then display the contents of array. the main() should then pass the array to the function "int fxn2 (int a[])"
    which returns the number of even numbers in a to main(). Main should then print out this number.


    #include<iostream.h>

    int fxn1 (int x, int array[]);
    int fxn2 (int a[]);
    void main()
    {
    int x, array[];
    cout<<"Enter a number: \n";
    cin>>x;
    cout<<fxn1 (x, array[])<<endl<<endl;
    cout<<fxn2 (array[i])<<endl;
    }

    int fxn1 (int x, int array[])
    {
    int num, multiplier=1;
    cout<<"How many multiples to display?\n";
    cin>>num;
    for (int i=0; i<num; i++)
    {
    array[i]=x*multiplier;
    multiplier++;
    }
    return array[i];
    }

    int fxn2 (int a[])
    {
    int even=0;
    i=0;
    do
    {
    if (a[i]%2==0)
    even++;
    i++;
    }
    while (i<)
    return even;
    }

    -- THE END!!!!!
    ok... something is messed up

  2. #2
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    First you need to include dynamic memory allocation.
    You cannot declare an empty array - int array[];
    You need to create a pointer - int *array;
    and dynamically allocate the size of it when you get the number of multiples.
    array = new int[num]

    I'm not exactly clear on all that the program is actually supposed to do but that will help a bit.

    Good luck

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie - cubic polynomial program - help!
    By jaffa in forum C Programming
    Replies: 1
    Last Post: 03-27-2006, 05:52 AM
  2. Replies: 10
    Last Post: 02-17-2005, 09:27 PM
  3. Program doesn't always do whats expected... any ideas? (newbie)
    By photoresistor in forum C++ Programming
    Replies: 4
    Last Post: 12-07-2002, 02:49 AM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. command line program, something wrong in the argv
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 09-26-2001, 09:36 AM