A little bit confused... - Functions - ...

I try to make this work and after put it into a class, but i cant find out where i got mistakes... i know they exist... please help me find out ...
thanks in advance :)

here is my code :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*  
	Copiright © 2011 Jumper007TM All Rights Reserved 
*/

#include <iostream>

using namespace std;

// We initialize a fuction to display the array at any time by simply using : DisplayArray(anArray[i])
void DisplayArray(int anArray[10000], int Start)
{
	//This will generate the array from the point (anArray[Start]) to the point of (anArray[10000])	
	for (int i=Start; i<=10000; ++i)
	{
		cout<<"The "<<i+1<<"th place in Array is occupied by"<<anArray[i]<<";\n";
	}
}

// We initialize another function, but this one will read the element fo the array by using: ReadArray(anArray[i])
void ReadArray(int anArray[10000], int Start)
{
	//This will let you give values to the array from the starting point (anArray[Start]) to the point of (anArray[10000])
	for (int i=Start; i<=10000; ++i)
	{
		cin>>anArray[i];
	}
}

// Here starts the real program
int main()
{
	int anArray[10000];
	int i, Start;
	
	cout<<"Give the start point value of the array: ";
	cin>>Start;
	
	// Here we use our function to read the array
	ReadArray(anArray[10000]);
	
	// Here we print out to check if the function worked
	DisplayArray(anArray[10000]);
	
	return 0;
}

/*  
	Copiright © 2011 Jumper007TM All Rights Reserved 
*/

Last edited on
Saying what the problem is will help...

By the way, a proper copyright notice would be
Copyright 2011 <name> <surname> All rights reserved
And you need it only once
the errors showed by my developer studio are:

1
2
3
4
5
6
7
8
9
cpp: In function `int main()':
cpp:41: error: invalid conversion from `int' to `int*'
cpp:23: error: too few arguments to function `void ReadArray(int*, int)'
cpp:41: error: at this point in file
cpp:44: error: invalid conversion from `int' to `int*'
cpp:13: error: too few arguments to function `void DisplayArray(int*, int)'
cpp:44: error: at this point in file
cpp:35: warning: unused variable 'i'
cpp:53:3: warning: no newline at end of file 
To pass an array to a function don't use subscript.
You need to pass a value for every parameter if you don't provide a default value on the function declaration.
Variable names in one function don't affect variables with the same name on other functions
O.O

ok, im not so good to understand what you just said ... (especially in english ... (subscript ? you mean my void ... ?))
Last edited on
subscript is this: a[b]
closed account (zb0S216C)
i is never used. You should receive a warning about this along the lines of Warning: unused variable 'i'.
I'm with Bazzy on this one.

There's a problem with both ReadArray( ) and DisplayArray( ). Firstly, what if you pass an array that has less than 10000 elements? Both of your method's for loops with over-step the array's boundaries, potentially crashing your program. Secondly, Start in both methods is never checked to make sure that it's a valid index.

P.S: It's Copyright not Copiright.
Last edited on
Topic archived. No new replies allowed.