1

Program needs to read the students' first name,last name and test scores.Suppose that class has 20 students.Use an array of 20 components of type studentType.

Output : last name followed by comma,space first name , score, revelant grade, and find the highest test score, print names of the students having the highest test score.
Name must be left-justified??? HOW

After I press n or N it doesn't output any names or scores ???
can someone pls let me know what is the problem???

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


 struct studentType
	{
		string studentFName, studentLName;
		int testScore;
		char grade;
	};

void printstudent (studentType student);

int main ( )
{	

	float avg, sum=0;
	char x;
	int i,j=0;
	struct studentType student[20];
	student[0];
	
	x = 'y';

	while ( (x == 'y') | ( x == 'Y') )
               {
				   j=j+1;

				   cout<<"Enter student's first name:"<<endl;   
					cin>>student[j].studentFName;

					cout<<"Enter student's last name:"<<endl; 
					cin>>student[j].studentLName;

					cout<<"Enter test score:"<<endl;
                    cin>>student[j].testScore;
                          
					 if (student[j].testScore>=90)
						 student[j].grade='A';
					 else if (student[j].testScore>=80)
						 student[j].grade='B';
					 else if (student[j].testScore>=70)
						 student[j].grade='C';
					 else if (student[j].testScore>=60)
						 student[j].grade='D';
					 else 
						 student[j].grade='F';

					cout<<"Enter 'y' for next student or"
                      <<" Enter 'n' or 'N'to end."<<endl;
					   cin>>x;
 }


int tempo=0; scanf("...", tempo);
return 0;
}

void printstudent (studentType student)
{	
	cout << student.studentLName<<", "<<student.studentFName
		 << " " << student.testScore
         << " " << student.grade<<endl;
	
}
Votes + Comments
Code tags on first post.
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by VernonDozier
0

Regarding the 'y' or 'Y' or "n' or 'N' test, don't confuse the | operator with the || operator in your if statement. You want the || operator.

Regarding the left justification, you have included iomanip, but you haven't used it. iomanip will help with setting the column widths and justification. Google "iomanip tutorial". It's a powerful tool.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.