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
#include <iostream>
usingnamespace 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
elseif(number<1 || number>100)
{
cout<<"\nOut of range.Enter between 1-100.\n";
continue;
} //invalid input,do again
if(maximum < number)
{
maximum = number;
}
elseif(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.