Question about Min and Max numbers

Hi all I'm new here. I have an assignment I'm working on. User enters positive numbers, program totals, averages, find min and max and displays to the user and user enters a negative number to exit program and console displays sum, average, min and max. I got everything but the min part. For some reason its dropped numbers off and I cant figure out why. Please point me in the right direction.

Thank you :)

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132



#include <iostream>			//include input and output library

int main()					//main function

{							// beginning of main function

using namespace std;		//using the standard namespace
int n;						//counter for the total number of input values
float in_value;				//variable to hold the current input value
float sum_of_in_values;		//variable to hold the running total
float average_value;		//variable for holding the average calculated
bool more;					//flag to indicate whether the just input
float max;					//variable for maximum user input number
float min;					//variable for minimum user input number
							// value is to be processed as one of the
							// input values or it is just a value to
							// indicate NO MORE
							//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
							//initialize variables properly
							//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
more = true;				//assume we have more input values to come in
n = 0;						//number of entries initialized
in_value = 0.0;				//user input variable initialized
sum_of_in_values = 0.0;		//sum of user entries variable initialized
average_value = 0.0;		// all values initialized
max = 0.0;					// max intialized
min = 100000000.0;			// min initialized

							//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
							// ask user for the first input value
							//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐

cout << "Please enter a non negative number (<0 = no more): ";
cin >> in_value;			//receive the value from user

if (in_value < 0)			//if the input value signifies the end then
	more = false;			//turn the flag to false to avoid entering
							// the major loop to do work
							//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
							//The major loop to process each incoming value
							//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
while (more == true)			//while this new input is an input value

	{

		n = n + 1;			//one more valid number has been accepted
		sum_of_in_values = sum_of_in_values + in_value;

		if (max < in_value)

			{
		
				max = in_value;

			}

		cout << endl ;		//Go to the next line on screen

							//‐‐‐‐‐‐‐‐‐ask for the next input value before end of loop

		cout << "Please enter the next non negagtive number (<0 = no more): ";
		cin >> in_value;	//receive value from user
		
		if (in_value < 0)
			more = false;	//no more input values from user

		if (in_value <= min)

			{

				if (in_value > 0) //sets minimum check
				min = in_value;   //to set minimum value we subtracted 1, sum_of_in_values = sum_of_in_values + in_value; 
								  //this would add 1, so if we subtract 1 to compensate it will give an accurate min num
			}
else
			min = min;

		
}							//end while
							//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
							// Now display the correct summary information
							//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
cout << endl;				//skip a line for readability on the screen

	if (n > 1)				//if user input is more than 1 execute this

		{

			average_value = sum_of_in_values / n ;										// calculate average of user input
			cout << "\nThere is a total of " << n << " input values." << endl;			// output total
			cout << "The average is: " << average_value << endl;						// output average on user input
			cout << "The maximum value of your entries is: " << max << endl;			// output of maximum numbers
			cout << "The minimum value of your entries is: " << min << endl;			// output of minimum numbers
			cout << "The total sum of all input is:  " << sum_of_in_values << endl;		// output of the sum of user numbers

		}					//end if (n > 1)

	else					// n is <= 1

		{

			if ( n == 1)	// begin if n == 1

				{

					cout << "Since you only keyed in one non negative number, the \n" ;
					cout << "average is the input value: " << sum_of_in_values <<".\n";
					cout << "The max is also the input value: " << max << endl;

				}			// end (if n == 1)

			else			//n is < 1

				{

					cout << "You have not input a valid entry. ";
					cout << "I cannot calculate the average. Please try again.\n" << endl;

				}			//end else n is < 1
	
	}						//end else n is <= 1

cout << "\n\nBye!\n\n" << endl;	//bye for exit and skip a line to make it clearer for the next time the program is ran

system("PAUSE");			//keep window showing results until user hits button to restart loop

return main();				//call to return to main function and rerun program until window is closed

}							// end of main function 
I'm sure its blatantly obvious to some of you. But this is my first time programming besides hello world. Please go easy :/
Hmmm.... try setting max and min to the first value entered before you enter the loop.
Could you be a little more specific? I know I have them initialized and they are supposed to show the user input max and min numbers. But where would I do that before the loop? Because they take on different values while in the loop?
Actually that was not very good advice, I copied your code and compiled it with that change and it seemed to work, that's why I suggested it. The real problem is that if your first number is the minimum, then it will not be recorded. You get the first value from user input before the loop, then in the loop it checks to see if it is the maximum, then requests a new number, then checks to see if it is the minimum. The first number entered never gets checked to see if it is the minimum.
Oh i see. Dang I cant believe I missed that. Added:

cout << "Please enter a non negative number (<0 = no more): ";
cin >> in_value;

if (in_value < 0)
more = false;

min = in_value; <------- added this


while (more == true)

compiled and boom everything works. I cant believe I missed that. Thank you for your help. Now to do some testing. Make sure I get no weird errors
Topic archived. No new replies allowed.