Min and max number

how to display min and max number that inserted by user without using array ?
My coding wont display min number.



#include <iostream>
using namespace std;
int main()
{

int scoreCount, numStudent ;
int max = 0;
int min = 0;
int totalScore = 0 ;
double score ;

cout << "Enter number of student : " ;
cin >> numStudent ;
cout << endl;

scoreCount = 1;
while (scoreCount <= numStudent)

{
cout << " Enter score " << scoreCount << " : " ;
cin >> score ;

scoreCount++ ;
totalScore+=score ;

if (score > max)
{
max = score;
}

else if (score < min)
{
min = score;
}
}

cout << " Total score is " << totalScore << endl;

cout << " The highest number is " << max << endl ;
cout << " The lowest number is " << min << endl ;


}
else if (score < min)

On that line, what is the value of min?
PLEASE learn to use code tags, they make reading and commenting on source code MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

HINT: you can edit your post and add code tags.

Some formatting & indentation would not hurt either

With that said:
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
#include <iostream>
#include <climits>  // for INT_MAX & INT_MIN

int main()
{
   std::cout << "Enter number of student : ";
   int numStudent;
   std::cin >> numStudent;
   std::cout << '\n';

   int max        { INT_MIN };
   int min        { INT_MAX };;
   int totalScore { };

   for (int scoreCount { 1 }; scoreCount <= numStudent; ++scoreCount)
   {
      std::cout << "Enter score " << scoreCount << " : ";
      int score;
      std::cin >> score;

      totalScore += score;

      if (score > max) { max = score; }

      else if (score < min) { min = score; }
   }

   std::cout << "\nTotal score is " << totalScore << '\n';

   std::cout << "The highest number is " << max << '\n';
   std::cout << "The lowest number is " << min << '\n';
}
Enter number of student : 4

Enter score 1 : 67
Enter score 2 : 45
Enter score 3 : 78
Enter score 4 : 98

Total score is 288
The highest number is 98
The lowest number is 45
Topic archived. No new replies allowed.