Finding a max and min numbers with user input

Hello everyone. I am working on a block of codes that will get the test scores from the user and it will calculate the average of the classroom,and output minimum score and maximum score, additionally it will show how many score entered by user. Here my codes

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
 #include <iostream>

using namespace std;

int main()
{
        int maximum=0;
        int number,sum=0;
        int minimum=0;
        int count=0;
        float average;

minimum = number;
maximum = number;


while(1)
{
 cout<<"Enter a number(999 to quit): ";
 cin>>number;

    if(number==999)
    break;  // enough asking for numbers

    else if(number<1 || number>100)
    {
        cout<<"\nOut of range.Enter between 1-100.\n";
        continue;
        } //invalid input,do again


            if(maximum < number)
                {
                maximum = number;
                }
             else
                if(minimum > number)
                {
                minimum = number;
                }

            sum+=number; //add to sum
            count++;         // increment count
}

average=float(sum)/float(count);

cout<<"\nYou entered "      << count << " numbers."<<endl;
cout<<"Their average is : "  <<average<<endl;
cout<<"Max number is : "    <<maximum<<endl;
cout<<"Min number is : "     <<minimum<<endl;
return 0;
}


It calculates the average properly, shows how many score was entered, it shows minimum score accurately but when it comes to maximum number it shows 2686728 all the time. I tried so many different input but maximum number is always the same. I am sure I am making a great logic mistake. Thanks for your time and attention.
1
2
3
4
5
6
7
8
  int maximum=0;
        int number,sum=0;
        int minimum=0;
        int count=0;
        float average;

minimum = number;
maximum = number;

"number" is undefined. You need to do int number=0,sum=0;

Also in this case the minimum will always be 0, because you can't enter less than 1.
Thanks James2250. That was very helpful
Topic archived. No new replies allowed.