Arrays within a function

Hello, im being asked to create a user defined array. Ive gotten that code down, but im having trouble defining the array within a call function. If anyone knows how to properly code an array within a call function that would be appreciated.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  int main() {
int i = 0, n = 0;
  float arr[100];

cout << "Enter total number of elements(1 to 100): ";
  cin >> n;
  cout << endl;
  

  for(i = 0; i < n; ++i)
  {
  cout << "Enter Number " << i + 1 << " : ";
  cin >> arr[i];
  }

  for(i = 1;i < n; ++i)
  {
   
   if(arr[0] > arr[i])
   arr[0] = arr[i];
  }
  cout << "Smallest Element = " << arr[0];
return 0;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int smallest_element(int array[], int size) {
	int value = array[0];
	for (i = 1; i < size; ++i) {
		if (value > array[i])
			value = array[i];
	}
	return value;
}

int main(){
	//...
	int smallest = smallest_element(arr, n);
	std::cout << "Smallest Element = " << smallest << '\n';
}
¿what are you trying to do that is giving you issues?
Im having trouble calling the size that the user wants for the array and then the elements of the array into the smallest_element function.
misread that...
calling the size? What does it mean?
its just how many locations the array has, or how many are in use, depending on what you are talking about. If 10 locations are in use, its 10.

Last edited on
yeah my terminology with c++ is trash. Still new to the language and how to correctly get my point across. Anyways I got my code to run the way I needed it to.
Topic archived. No new replies allowed.