| | |
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 |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





