954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

need some help

I have these question and I need some help from you :
Assume that the maximum number of students in a class is 50. Write a program that reads students' names followed by their test score from a file and outputs the following:

a. class average
b. Names of all the students whose test scores are below the class average, with an appropriate message
c. Highest test score and the names of all the students having the highest score

and this is my answer , and I dont know what is the problem with it , becuase the out put was not what I need the number on the screen like this -234567877.87 .

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{     double scores[50];
      double avg ;    
      double sum=scores[0],max = scores[0];
      string names[50];  
	  int count=0;
	  ifstream data;
	  data.open("in.txt");

	while (!data.eof()&&count<=50)

	{
		data>> names[count] >> scores[count] ;
					count++;
	}
		
	for (int m=1; m<count; m++)
	{

		sum+= scores[m];

			
			if (scores[m]>max)
			{
				max= scores[m];
				
			}
	}

	avg= sum/count;

	cout<<" class average is : "<<avg<<endl;
	cout<<"Students whose test scores are below the class average are :"<<endl;

	for (int n=0; n<count; n++)
	{
		if (scores[n]<avg)
			cout<<names[n]<<endl;
	}

	cout<<"Highest test score is : "<<max<<endl;
	cout<<"Students having the highest score are :"<<endl;

		for (int i=0; i<count; i++)
		{
			if (scores[i]==max)
			cout<<names[i]<<endl;
		}

      data . close ();
	return 0;
}
bis student
Newbie Poster
16 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

try this

.....
.....
int main()
{     double scores[50];
      double avg ;    
      
      string names[50];  
	  int count=0;
	  ifstream data;
	  data.open("in.txt");

	while (!data.eof()&&count<=50)

	{
		data>> names[count] >> scores[count] ;
					count++;
	}

        <strong>double sum=scores[0],max = scores[0];</strong>

	for (int m=1; m<count; m++)
	{

		sum+= scores[m];

			
			if (scores[m]>max)
			{
				max= scores[m];
				
			}
	}
....
....
amt_muk
Light Poster
48 posts since May 2005
Reputation Points: 14
Solved Threads: 3
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You