Hi, im working on a project for school and Im having a little trouble. The problem states:
Write a program that reads students names followed by their test scores. The program should output each students name folloed by the test scores and the relevent grade. It should also find and print the highest test score and the name of the students having the highest test score.
Student data should be stored in a struct variable of type studentType which has 4 components for fist and last name, test score and grade. Suppose the class has 20 students. Use an array of 20 components of type studentType

Here is what I have so far.

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

void StuRead(indata, studentType students[]);
char AssignGrade(char LetterGrade, studentType students[]);  //here im getting an error: student type has not been declared
void Highest();
void Print(students[]);



struct studentType
{
        string fName, lName;
        int Scores;
        int Tests;
        char grade;
};

studentType students[20];

main ()
{

ifstream inFile;
ofstream outFile;

inFile.open("Studinfo.txt");
outFile.open("Stinfo.out");


StuRead(infile, studentType students[]);





return 0;
}


void StuRead(ifstream& indata, studentType students[])
{
int x;

x = 0;
for (x = 1; x < 20; x++)
  {
  infile >> students[x].lName
         >> students[x].fName
         >> students[x].Tests;
  }

}




char AssignGrade(char LetterGrade, studentType students[])
{
if(score >= 90)
        studentType.grade = 'A';  //for these lines im getting this error: expected unqualified-id before '.' token
else if(score >= 80)
        studentType.grade = 'B';
else if(score >= 70)
        studentType.grade = 'C';
else if(score >= 60)
        studentType.grade = 'D';
else
        studentType.grade = 'F';


}



void Highest(students[20])
{
int highTest = 0;
        for(x = 0; x < 20; x++)
        {
          if(x > highTest)
                highTest = x;

        }


}

I just showed a few of the errors but please tear this thing apart and give me any advice u can.
If anyone could help me out a little I would greatly apreciate it :) Thanx alot!

Recommended Answers

All 3 Replies

move line 7 char AssignGrade(char LetterGrade, studentType students[]); to after you declare you studentType struct on lines 13-19

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
 void StuRead(indata, studentType students[]);
  // AssignGrade() function was here
void Highest();
void Print(students[]);
   struct studentType
{
        string fName, lName;
        int Scores;
        int Tests;
        char grade;
};

char AssignGrade(char LetterGrade, studentType students[]); // this will work here.

the reason for this is that when the compiler comes in it sees the studentType variable but it does not know what it is because you haven't declared it yet in the code.

Also just for your information on line 21 you have studentType students[20]; you really do not want to do this. what you have done is declared a global variable and as such it can be used in any function in the program and could lead to errors or unexpected behavior. i know there is a thread on daniweb but i don't remember where its at about global variables

Hey thanx alot for your infut man! im still workin on the code and changing things but if u have anymore tips for me I would apreciate it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.