Need help On Project

I have to write a program that find the biggest and smallest number in an array.
Here is Source 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
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <fstream>
#include <iomanip>


void	loadArray();
void	smallestLocation(int, int []);
void	largestLocation(int, int []);
void	printSmallestLargest(int [], int, int);
 

using namespace std;

int main (){ 
	



	return 0;
}
void loadArray(){

	srand(time(NULL));
	int max= rand() % 75 + 25;	
	int iArray [100]; 
	for (int i=0; i<max; i++){
		
		iArray[i] = rand()%1000 + 1;
	
	}

}

void smallestLocation(int &max, int iArray[]){
	int large = 0,lLocation;
	for (int i=0; i<max; i++){
		if(iArray[i]>large)
		large= iArray[i];
		lLocation=i;
	}
	
}

void largestLocation(int &max, int iArray[]){
	int small= 100, sLocation;
	for (int i=0; i<max; i++){
		if(iArray[i]<small)
		small=iArray[i];
		sLocation=i;
	}

}
	


void printSmallestLargest(int iArray[], int &sLocation, int &lLocation){
cout << " The largest number in the array is " << iArray[lLocation] << "\nThe smallest number in the array is " << iArray[sLocation];
	
}


Here is requirements:
1. loadArray --- Is a function that will store values in the array. The maximum number of values to be stored in the array should be between 25 and 100. Generate a random number in the interval [25,100] which will be the actual number of values contained in the array. This value will be the actual number of legitimate values stored in the array.
a. Once this value has been determined, use the random number generator to store values in your integer array from 1 to 1000.
2. smallestLocation --- is a function that returns the subscript or location in the array of the smallest number in the list.
3. largestLocation --- is a function that returns the subscript or location in the array of the largest number in the list.
4. printSmallestLargest --- is a function that will print the largest number and the smallest number in the list. Note: This function should have as parameters the array and the subscripts of the smallest and largest items in the array. Do not use a separate variable to contain the largest or smallest number in the list.


I'll fix function names as they are redundant.
How can i make it run through each function in order then quit?
Last edited on
......
To run them, you need to call the function you want.
void LoadArray seems redundant because iArray is not a global variable. Any your attempt will be destroyed when the function finished the performing. And all other functions, they should have a returning value, such as in your case (int <function name>())
In my opinion, your code should be changed. Here is an example :
1
2
3
4
5
6
7
int *LoadArray(){
[...]
return iArray;}
//All other functions
int <name>(){
[...]
return result}

The size of this array is always 100, so all remaining functions using this array you should always specify the size is 100 (You can change and make a new parameter for function LoadArray if you need)
For example, usage of the code
1
2
3
4
5
6
int main(){
int *iArray = LoadArray();
int smallLoc = smallestLocation(100,iArray);
int largeLoc = largestLocation(100, iArray);
printSmallestLargest(iArray,smallLoc, largeLoc)
}

"Smallest" returns sLocation and 'Largest' returns lLocation. Do you know returning value of a function?? :)
Last edited on
the values of the array are unknown, that's why theirs random number generators. so sLocation and lLocation are the location in the array where the smallest and largest value are.

we get an automatic zero if we use global variables. so i need to know how to run each function and pass parameters correctly

i think i have iArray passed to other functions as a parameter

thanks for your help
Last edited on
Topic archived. No new replies allowed.