Help!! Histogram Array
Nov 14, 2013 at 5:55am UTC
I need help with, i would also appreciate a little explanation so i can comprehend whats going on.
A histogram showing the number of students who received scores in the following ranges: 0 thru 5, 6 thru 10, 11 thru 15, 16 thru 20, 21 thru 25, and 25 thru 30. The histogram should look something like this:
Frequency
---------
Score Obtained By 5 10 15 20 25
----- ----------- ----|----|----|----|----|
0...5 1 *
6...10 7 *******
11...15 10 **********
16...20 3 ***
21...25 2 **
26...30 2 **
my current code:
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
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
const int ARRAY_SIZE = 31;
const int CLASS_SIZE = 25;
char answerkey[ARRAY_SIZE];
char studentanswers[ARRAY_SIZE];
char student_name[64];
int count = 0;
int i = 0;
int sum = 0;
int mean = 0 ;
ifstream inputFile;
inputFile.open("xfile.txt" );
if ( !inputFile.good() )
{
cout << "Error opening file" << endl;
return EXIT_FAILURE;
}
inputFile.getline(answerkey, ARRAY_SIZE);
cout << answerkey<< endl;
for (i = 0; i < CLASS_SIZE; i++)
{
int score = 0;
inputFile.getline(student_name, 64);
cout << student_name << endl;
inputFile.getline(studentanswers, ARRAY_SIZE);
cout << studentanswers << endl;
for ( count = 0; count < ARRAY_SIZE; count++)
if (answerkey[count] == studentanswers[count])
score = score + 1;
else
score = score;
sum = score + sum;
cout << score << endl;
}
cout << endl <<"The class mean is " << (mean = sum / 25 ) << endl;
return 0;
}
Last edited on Nov 14, 2013 at 5:27pm UTC
Nov 14, 2013 at 10:31am UTC
Please use code tags when posting code, to make it readable.
Nov 14, 2013 at 5:28pm UTC
Fixed, any one able to help me?
Topic archived. No new replies allowed.