subroutine & pointers help!

I created a program based on the instruction below, but do not know about this pointer, subroutine and Void issue. Can someone fix my C++ base on the below instuctions: This way I know how to do it. Please write it. If you tell me what to replace, I will be lost.
Thank you so so much


Write a program that finds the minimum and maximum value of an array with 10 numbers of your choice.
You need to use a subroutine that takes as argument the array, the size of the array, and the pointers to two variables for the min and the max. To pass an array to a subroutine you need to define it as
void find_min_max(float list[], int size, float *min, float *max){


#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
int numbers[10];
int smallest=0;
int largest=0;
int temp=0;
}

for (int i=0; 1<10; i++)
{
cout<<"please enter number"<< i +1<< ":" << endl;
cin>> numbers[1];

}
smallest=numbers[0];
largest=numbers[0];
}

for (int i=0; 1<10; i++)

{
temp=number[i];
if (temp<smallest)
smallest-temp;

if (temp>largest)
largest=temp;
}

cout<<"largest number is:" << largest<< endl;
cout<<"smallest number is:" << smallest<< endl;

return 0;
}
Last edited on
The "subroutine" is a synonym for "function". See http://www.cplusplus.com/doc/tutorial/functions/
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
#include <iostream>
#include <stdlib.h>

using namespace std;

void find_min_max (float list[], int size, float *min, float *max)
{
  float temp;

  *min = list[0];
  *max = list[0];

  for (int i = 1; i < size; i++)
  {
    temp = list[i];
    if (temp < *min)
      *min = temp;

    if (temp > *max)
      *max = temp;
  }
}

int main ()
{
  float numbers[10], smallest, largest;
  
  for (int i = 0; i < 10; i++)
  {
    cout << "please enter number " << i + 1 << ": " ;
    cin >> numbers[i];
  }
  find_min_max (numbers, 10, &smallest, &largest);

  cout << "largest number is:" << largest << endl;
  cout << "smallest number is:" << smallest << endl;
  
  system ("pause");
  return 0;
}
Thank you so much. I will look at this and learn it. My coding did exactly what it was supposed to do but not as per instructions.

THank you so much. I appreciate this a lot.

Topic archived. No new replies allowed.