### 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:
 ``1234567891011121314151617181920212223242526272829303132`` ``````#include #include // 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.