Please help

I have this lab exam that i really don't know what to do. The problem is here:
Create a program that holds an array containing 5 integers. Create two methods that accept the array. The first method named lowest returns the lowest from the 5 numbers while the second method returns the highest number from the list. Determine the highest and lowest numbers without sorting the numbers. Your output should contain the original list of number, the highest and the lowest number from the list. Supply the necessary values for the array.
Please help me. I don't know what to put for my prof didn't teach us anything about this. Thanks for your help :)

No worries, I will stop what I am doing and do the code for you at no cost. Now on the serious side, what have you code so far? You are right, the professor won't teach you how to solve the problem, but you should be able to apply what you have learned in your course.
Once you have done some of the code, then you can provide specific problems that you are having with your work.
HINT: Read the array chapter or section of your book. Good luck.
I only done the max value and she said that we need to define first before declaring. And then my head goes boom. And so many errors came out. Thanks for your concern. Here's the code I have done so far.
int num[5]
int x;
int y;

int max(int num1){
for (int z=0;z<5;z++){
y=num[z];
}
}
return y;

int main(){
cout<<"Type Integers:"<<endl;
for(x=0;x<5;x++)
{
cin>>num[x]
}
cout<<"The Highest Integer is:"<<max(y)<<endl;
return 0;
}
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
int num[5]  // Missing the semi-colon. I would discourage global variables.
int x; // I would discourage global variables.
int y; //I would discourage global variables.

 // This function is supposed to be determine the highest number.
// But it wont do it, because you are not comparing the numbers.
// The paremeter num1 is not being used inside the max function.
int max(int num1){ 
	for (int z = 0; z<5; z++){
		y = num[z]; 
		            // You may get an additional error due to putting multiple
		            // values into a single variable.

	}
}
return y; // This return is outside the function max.

int main(){
	cout << "Type Integers:" << endl;
	for (x = 0; x<5; x++)
	{
		cin >> num[x] 
	}
	cout << "The Highest Integer is:" << max(y) << endl;
	return 0;
}


I broke the problem into parts that may give you a head start:

Create a program that holds an array containing 5 integers
for (define and initialize the counter; counter < Total Number of Integers; Increment the counter)
ask the user for the number input for every iteration;

The first method named lowest returns the lowest from the 5 numbers.
Define and initialize a variable with the first integer number to determine the lowest.
for (define and initialize the counter; counter < Total Number of Integers; Increment the counter)
if (iterated numbers by the counter < Defined and initialized a variable with the first integer number to determine the lowest.)
then, the Defined and initialized a variable with the first integer number to determine the lowest is equal to the lowest number in the iterated numbers by the counter.

The second method named highest returns the lowest from the 5 numbers.
Steps are similar to lowest, but use the > operator.

Your output should contain the original list of number
for (define and initialize the counter; counter < Total Number of Integers; Increment the counter)
display the output of the iterated numbers inputted by the user;

display the highest and the lowest number from the list.
Output the highest and lowest value of the list in cout statements.
Last edited on
I really don't know how to define first. I tried some of the examples and did this. This problem really torture me a lot. T^T

int max(int a[5],int x,int y) And this is an error. How can I put array in a function?
Here is an example of an array function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
double a(const double b[], int c)
{
	double d;

	d = b[0];

	for (int e = 1; e < c; e++)
	{
		if (b[e] < d)
			d = b[e];
	}

	return d;
}

Last edited on
Once you show your updated code, then we could help more,
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
template<typename T> T max(T* array , size_t size)
{
	T value = array[0];
	size_t index = 1;
	while (index < size)
	{
		if (array[index] > value)
			value = array[index];
		index++;
	}
	return value;
}
template<typename T> T min(T* array, size_t size)
{
	T value = array[0];
	size_t index = 1;
	while (index < size)
	{
		if (array[index] < value)
			value = array[index];
		index++;
	}
	return value;
}

int main()
{

	int arraa[] = { 3, 6, 78, 9 };
	auto value = max<int>(arraa, 4);
	auto value2 = min<int>(arraa, 4);
	return EXIT_SUCCESS;
}
Topic archived. No new replies allowed.