Answer to Question #290109 in C++ for mr.unknown

Question #290109

Write a program that declare an array of size 25 consisting of students’ test scores in the range 0–200. The user may input any score in the array. 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)


1
Expert's answer
2022-01-24T08:04:04-0500
#include<iostream>

using namespace std;

int main()
{
	int arr[25]={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};
	
	int ranges[8]={0,0,0,0,0,0,0,0};
	
	for(int i=0;i<25;i++)
	{
		if(arr[i]>=0&&arr[i]<=24)
			ranges[0]++;
		else if(arr[i]>=25&&arr[i]<=49)
			ranges[1]++;
		else if(arr[i]>=50&&arr[i]<=74)
			ranges[2]++;
		else if(arr[i]>=75&&arr[i]<=99)
			ranges[3]++;	
		else if(arr[i]>=100&&arr[i]<=124)
			ranges[4]++;
		else if(arr[i]>=125&&arr[i]<=149)
			ranges[5]++;
		else if(arr[i]>=150&&arr[i]<=174)
			ranges[6]++;
		else if(arr[i]>=175&&arr[i]<=200)
			ranges[7]++;
	}
	cout<<"Number of scores in ranges:";
	cout<<"\n0 - 24: \t"<<ranges[0];
	cout<<"\n25 - 49:\t"<<ranges[1];
	cout<<"\n50 - 74:\t"<<ranges[2];
	cout<<"\n75 - 99:\t"<<ranges[3];
	cout<<"\n100 - 124:\t"<<ranges[4];
	cout<<"\n125 - 149:\t"<<ranges[5];
	cout<<"\n150 - 174:\t"<<ranges[6];
	cout<<"\n175 - 200:\t"<<ranges[7];			 
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment