Minimum and Maximum values returning as "0"

My program compiles and runs, but is returning "0" as the value for the minimum and maximum values. What am I doing wrong?

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  #include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main()

{

 double n1, n2, n3, i;
 char y;
 int minimum;

	cout<<"This program will calculate the min, max, and mean of a set of three numbers.\n\n"; 
	cout<<"Please enter numbers between 1 and 1000.\n\n";
		

	do{
		cout<<"Please enter your first number:\n\n";
		cin>>n1;
	  }while(n1<=0 || n1>=1000);

	do{	  
		cout<<"Please enter your second number:\n\n";
		cin>>n2;
	  }while(n2<=0 || n2>=1000);

	do{
		cout<<"Please enter your third number:\n\n";
		cin>>n3;
	  }while(n3<=0 || n3>=1000);


	cout<<"You have entered the following numbers:\n";
	cout<<n1<<"\n"<<n2<<"\n"<<n3<<"\n\n";

	cout<<"The minimum value is:"<<minimum<<"\n\n";

	
return 0;
}


//create minimum function
int minimum()

{

 int x, y, z;
 int lowest, highest;

	if (x<y)

		{
			lowest = x;
			highest = y;
		}
	else

		{
			lowest = y;
			highest = x;
		}

	if (z<lowest)

		{
			lowest = z;
		}

	else if (z>highest)

		{
			highest = z;
		}

//end of minimum function		
}
Your not setting the value of minimum anywhere.
you have not implemented the function you created. you will need to use your minimum function, and i think with the way you have it set up you will want to have 3 parameters passed to your function so that you can access user input.
1
2
3
4
5
int minimum(int input1, int input2, int input3) //this is your method declaration
return lowest;// the return your method needs

minimum=minimum(n1,n2,n3)//implementation & setting your variable

as for setting minimum to a number you are going to need to have your method a number and have your var = lowest
Last edited on
changed up a few things based off of your advice, but now my code will not compile. I am getting the "expected initializer" error

[cod#include <iostream>
#include <iomanip>
#include <stdio.h>
using namespace std;


int main()
int minimum(int x, int y, int z)

{

float n1, n2, n3, i;
char y;


cout<<"This program will calculate the min, max, and mean of a set of three numbers.\n\n";

cout<<"Please enter numbers between 1 and 1000.\n\n";


do{
cout<<"Please enter your first number:\n\n";
cin>>n1;
}while(n1<=0 || n1>=1000);

do{
cout<<"Please enter your second number:\n\n";
cin>>n2;
}while(n2<=0 || n2>=1000);

do{
cout<<"Please enter your third number:\n\n";
cin>>n3;
}while(n3<=0 || n3>=1000);


cout<<"You have entered the following numbers:\n";
cout<<n1<<"\n"<<n2<<"\n"<<n3<<"\n\n";


getch();

cout<<"The minimum value is:"<<lowest<<"\n\n";


return 0;
}


//create minimum function
minimum (int x, int y, int z)

{

int x, y, z;
int lowest, highest;

if (x<y)

{
lowest = x;
highest = y;
}
else

{
lowest = y;
highest = x;
}

if (z<lowest)

{
lowest = z;
}

else if (z>highest)

{
highest = z;
}

//end of minimum function
}
e][/code]
The error message also comes with a line, telling you which line to start looking at.

That said:

1
2
int main()
int minimum(int x, int y, int z)


This is just plain wrong.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
namespace nih{
   double min(double a, double b);
}

int main(){
   double x, y;
   std::cin >> x >> y;
   double minimum = nih::min(x, y);
   std::cout << minimum << '\n';
}

double nih::min(double a, double b){
   double lowest = a;
   if (b<a)
      lowest = b;
   return lowest;
}
Topic archived. No new replies allowed.