| | |
need some help
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
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 .
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 .
C++ Syntax (Toggle Plain Text)
#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; }
there are always hope
•
•
Join Date: May 2005
Posts: 48
Reputation:
Solved Threads: 3
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++;
}
double sum=scores[0],max = scores[0];
for (int m=1; m<count; m++)
{
sum+= scores[m];
if (scores[m]>max)
{
max= scores[m];
}
}
....
....![]() |
Other Threads in the C++ Forum
- Previous Thread: HeLP I need it today
- Next Thread: seeking a Project idea on c++
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets





