Here is a simpler piece of code to implement your program and I find it considerably easier to understand. Primarily because it uses several loops instead of explicit code.
int main()
{
const int binCount = 5;
const int binLimits[ binCount ] = { 19, 39, 59, 79, 100 };
int markBins[ binCount ] = { 0 };
int inputCount = 0;
std::cout << "Enter number of students : ";
std::cin >> inputCount;
if( inputCount < 1 )
return 0;
int * marks = new int[ inputCount ];
int mark;
for( int n = 0; n < inputCount; ++n )
{
std::cout << "\nPlease enter mark for student " << n << " : ";
std::cin >> mark;
if( ( mark < 0 ) || ( mark > 100 ) )
{
std::cout << "Error - marks may range from 0 to 100" << std::endl;
return 0;
}
marks[ n ] = mark;
}
int highMark = -1;
int lowMark = 1000;
double sumMarks = 0;
for( int i = 0; i < inputCount; ++i )
{
sumMarks += marks[ i ];
if( highMark < marks[ i ] )
highMark = marks[ i ];
if( lowMark > marks[ i ] )
lowMark = marks[ i ];
for( int n = 0; n < binCount; ++n )
{
if( mark <= limits[ n ] )
{
++bins[ n ];
break;
}
}
}
std::cout << std::endl << std::endl;
int lastMin = 0;
for( int n = 0; n < binCount; ++n )
{
std::cout << lastMin << " - " << binLimits[ n ] << std::endl;
for( int m = 0; m < markBins[ n ]; ++m )
std::cout << " *";
std::cout << std::endl;
lastMin = binLimits[ n ] + 1;
}
std::cout << std::endl;
std::cout << "highest Mark = " << highMark << std::endl;
std::cout << std::endl;
std::cout << "lowest Mark = " << lowMark << std::endl;
std::cout << std::endl;
double avgmark = sumMarks / (double) inputCount;
std::cout << "Average Mark = " << avgmark << std::endl;
delete [] marks;
return 0;
}
Here is the output from a file of 50 random values :
0 - 19
* * *
20 - 39
* * * * * * * * * * *
40 - 59
* * * * * * *
60 - 79
* * * * * * * * * * * * * * * *
80 - 100
* * * * * * * * * * * * *
highest Mark = 98
lowest Mark = 5
Average Mark = 59.62
and here is the file used :
50
26
60
50
71
5
96
86
54
47
64
36
79
98
62
88
58
38
33
25
46
21
31
23
35
60
40
82
84
10
98
93
65
76
79
69
28
84
61
17
97
61
75
71
92
53
92
37
88
68
69
Note that this does not solve your problem exactly because I don't want to just give you the answer. You will have to adjust this code to do what you want. The point of homework and quizzes is to learn something and you won't if someone does all the work for you. Hopefully this gives you some different ideas on how to approach this problem.
One of the key things I mentioned earlier was the use of loops and arrays. Explicit code and data are rarely the best way to go when they are both repeated, as yours is. When you can organize your code into loops and arrays (and functions) it makes it much easier to extend and change things. In this case, the bin count and limits are different than yours and it is very, very easy to change them to match yours. That is something YOU will have to do. I also omitted the count of passes and failures and you will need to add those also. Here's a hint : add them in the section with the comment "process the data."