what's wrong with my newbie program??

Printable View

• 09-14-2001
insoolated
what's wrong with my newbie program??
This is a homework problem :D
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 :(
• 09-14-2001
taylorguitarman
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