Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

HELP I dont know what Ive done wrong. It does the program it just doesnt count t

ID: 3765756 • Letter: H

Question

HELP I dont know what Ive done wrong. It does the program it just doesnt count the students and test scores.

#include<iostream>

#include<fstream>

#include<iomanip>

#include<string>

using namespace std;

void readTestScores(ifstream &inFile, int score[]);

void findNumberOfStudentsInEachRange(int[], int[]);

void displayResult(int[], int[]);

const int TOTAL_RANGES=8;

const int RANGE_SIZE=25;

const int MAX_STUDENTS=50;

int numberOfStudents;

int main()

{

  

string fileName;

  

ifstream inFile;

  

int score[MAX_STUDENTS];

int range[TOTAL_RANGES];

  

cout<<"Enter the file name:";

cin>>fileName;

  

inFile.open(fileName);

  

if(!inFile)

{

cout<<"The file"<<fileName<<"is not found."<<endl;

  

system("pause");

return 1;

}

  

readTestScores(inFile, score);

  

findNumberOfStudentsInEachRange(score, range);

  

displayResult(score, range);

  

inFile.close();

system("pause");

return 0;

}

void readTestScores(ifstream &inFile, int score[])

{

int testScore;

  

inFile>>testScore;

  

numberOfStudents=0;

  

while(inFile && numberOfStudents < MAX_STUDENTS)

{

  

score[numberOfStudents]=testScore;

  

numberOfStudents++;

  

inFile>>testScore;

}

}

void findNumberOfStudentsInEachRange(int score[], int range [])

{

  

int testScore;

int scoreRange;

  

for(int i =0; i < TOTAL_RANGES; i++)

range[i]=0;

for(int i=0; i < numberOfStudents; i++)

{

testScore= score[i];

  

if(testScore >= 0 && testScore <= 24)

range[0]++;

  

else if(testScore >= 25 && testScore <= 49)

range[1]++;

  

else if (testScore >= 50 && testScore <= 74)

range[2]++;

  

else if(testScore >= 75 && testScore <= 99)

range[3]++;

  

else if (testScore >= 100 && testScore <= 124)

range[4]++;

  

else if (testScore >= 125 && testScore <= 149)

range[5]++;

  

else if (testScore >= 175 && testScore <= 200)

range[7]++;

  

else

{

cout << "All of test scores should be in the range of 0 to 200." << endl;

system("pause");

exit(1);

}

}

}

void displayResult(int score[], int range[])

{

  

int startRange=0;

int endRange=24;

  

cout<< "The test scores scored in the file."<<endl;

for (int i=0; i<numberOfStudents; i++)

  

cout<<score[i] <<" ";

cout<<endl;

  

cout<< "The number of test scores stored in the file:"<<numberOfStudents<<endl;

  

for (int i=0; i < TOTAL_RANGES; i++)

{

cout<< "The number of students between the range of scores"<< startRange<<"-"<<endRange<<":"<<range[i]<< endl;

  

startRange += RANGE_SIZE;

  

endRange += RANGE_SIZE;

  

if(endRange == 199)

endRange = 200;

  

}

}

write a program that reads a file consisting of student's tests scores in the range 0-200. It should then determine the number of students having scores in each of the following ranges: 0-24, 25-49, 50-74, 75-99, 100-124, 125-149, 150-174, and 175-200. Output the score ranges and the number of students. (Run your program with the following input data: 76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149, 176, 200, 87, 35, 157, 189.)

Explanation / Answer

you have done error in void findNumberOfStudentsInEachRange(int score[], int range [])

you forgot to add condition for scores from 150-174

else if (testScore >= 150 && testScore <= 174)
range[6]++;

please find the corrected code

i have tested the below code inhttp://www.tutorialspoint.com/compile_cpp11_online.php ita working fine if you remove pause statements


#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
using namespace std;

void readTestScores(ifstream &inFile, int score[]);
void findNumberOfStudentsInEachRange(int[], int[]);
void displayResult(int[], int[]);

const int TOTAL_RANGES=8;
const int RANGE_SIZE=25;
const int MAX_STUDENTS=50;

int numberOfStudents;

int main()

{
  
string fileName;
  
ifstream inFile;
  
int score[MAX_STUDENTS];
int range[TOTAL_RANGES];
  
cout<<"Enter the file name:";
cin>>fileName;
  
inFile.open(fileName);
  
if(!inFile)
{
cout<<"The file"<<fileName<<"is not found."<<endl;
  
system("pause");
return 1;
}
  
readTestScores(inFile, score);
  
findNumberOfStudentsInEachRange(score, range);
  
displayResult(score, range);
  
inFile.close();
system("pause");
return 0;
}

void readTestScores(ifstream &inFile, int score[])

{
int testScore;
  
inFile>>testScore;
  
numberOfStudents=0;
  
while(inFile && numberOfStudents < MAX_STUDENTS)
{
  
score[numberOfStudents]=testScore;
  
numberOfStudents++;
  
inFile>>testScore;
}
}

void findNumberOfStudentsInEachRange(int score[], int range [])

{
  
int testScore;
int scoreRange;
  
for(int i =0; i < TOTAL_RANGES; i++)
range[i]=0;
for(int i=0; i < numberOfStudents; i++)
{
testScore= score[i];
  
if(testScore >= 0 && testScore <= 24)
range[0]++;
  
else if(testScore >= 25 && testScore <= 49)
range[1]++;
  
else if (testScore >= 50 && testScore <= 74)
range[2]++;
  
else if(testScore >= 75 && testScore <= 99)
range[3]++;
  
else if (testScore >= 100 && testScore <= 124)
range[4]++;
  
else if (testScore >= 125 && testScore <= 149)
range[5]++;
else if (testScore >= 150 && testScore <= 174)
range[6]++;

else if (testScore >= 175 && testScore <= 200)
range[7]++;
  
else
{
cout << "All of test scores should be in the range of 0 to 200." << endl;

  system("pause");
exit(1);
}
}
}

void displayResult(int score[], int range[])
{
  
int startRange=0;
int endRange=24;
  
cout<< "The test scores scored in the file."<<endl;
for (int i=0; i<numberOfStudents; i++)
  
cout<<score[i] <<" ";
cout<<endl;
  
cout<< "The number of test scores stored in the file:"<<numberOfStudents<<endl;
  
for (int i=0; i < TOTAL_RANGES; i++)
{
cout<< "The number of students between the range of scores"<< startRange<<"-"<<endRange<<":"<<range[i]<< endl;
  
startRange += RANGE_SIZE;
  
endRange += RANGE_SIZE;
  
if(endRange == 199)
endRange = 200;
  
}
}