structures problem

hello all, having a slight problem trying to solve this, using visual studio 2010....i have to write a structure that stores a students name, id, 3 test scores, figure out the average grade and overall i.e. if the average is 92 then an a, 87 an b, etc. ill post the code, then the errors to follow
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

struct Student
{
string name;
int idNum;
int test1;
int test2;
int test3;
double avg;
double gpa;
};

void getData(Student *); // Function prototype

int main()
{
Student freshman;

cout << "Enter the following student data:\n";
getData(&freshman);
cout << "\nHere is the student data you entered:\n";


cout << setprecision(3);
cout << "Name: " << freshman.name << endl;
cout << "ID Number: " << freshman.idNum << endl;
cout << "average test score: " << freshman.avg << endl;
cout << "course grade: " << freshman.gpa << endl;
return 0;
}



void getData(Student *s)
{

cout << "Student name: ";
getline(cin, s->name);


cout << "Student ID Number: ";
cin >> s->idNum;


cout << "test 1: ";
cin >> s->test1;

cout << "test 2: ";
cin >> s->test2;

cout << "test 3: ";
cin >> s->test3;

s-> avg = (test1 + test2 + test3)/3;
if (avg >= 90)
s-> gpa = "A";
else if (avg >= 80)
s-> gpa = "B";
else if (avg >= 70)
s-> gpa = "C";
else if (avg >= 60)
s-> gpa = "D";
else
avg = "f";

}
Error 1 error LNK2001: unresolved external symbol _mainCRTStartup C:\Documents and Settings\allisa\my documents\visual studio 2010\Projects\course grades\course grades\LINK course grades
Error 2 error LNK1120: 1 unresolved externals C:\Documents and Settings\allisa\my documents\visual studio 2010\Projects\course grades\Debug\course grades.exe course grades
3 IntelliSense: identifier "test1" is undefined c:\documents and settings\allisa\my documents\visual studio 2010\projects\course grades\course grades\course grades.cpp 58 15 course grades
(the same for test2 and test3)
6 IntelliSense: identifier "avg" is undefined c:\documents and settings\allisa\my documents\visual studio 2010\projects\course grades\course grades\course grades.cpp 59 8 course grades
7 IntelliSense: a value of type "const char *" cannot be assigned to an entity of type "double" c:\documents and settings\allisa\my documents\visual studio 2010\projects\course grades\course grades\course grades.cpp 60 13 course grades
7 IntelliSense: a value of type "const char *" cannot be assigned to an entity of type "double" c:\documents and settings\allisa\my documents\visual studio 2010\projects\course grades\course grades\course grades.cpp 60 13 course grades
Error 1 error LNK2001: unresolved external symbol _mainCRTStartup

It seems you've selected the wrong project type. Try creating the project again, but this time select "Empty Project".

3 IntelliSense: identifier "test1" is undefined c:\documents and settings\allisa\my documents\visual studio 2010\projects\course grades\course grades\course grades.cpp 58 15 course grades (the same for test2 and test3)

This is due to this line:

s-> avg = (test1 + test2 + test3)/3;

You're missing s-> in front of test1, test2, and test3. Same thing for all the instances of avg in your if statements.

7 IntelliSense: a value of type "const char *" cannot be assigned to an entity of type "double"

This error is self-explanatory. You can't do something like s-> gpa = "A"; when gpa is a double. If all you want to store is the letter grade then I suggest that you make gpa a char instead.
thank you, and that resolved about 95% of my problems. i know have 5 errors, all repeats of the number 7 above, just changed to that const char cannot be of type char
That's a type mismatch. Basically you're trying to shove one data type into a different variable type.
char != char * != const char
thanks i got it to work!
Hi, I have a question very similiar to this one. I'm given an assignment to create a student grade structure, and calculate the numeric grades and letter grades.

And the part I'm having trouble with is that, we are also asked to used a function to catch duplicate student ID. i.e. if one ID has been entered already, we'd tell the user to try another.

Here is what I have done so far:
#include <iostream>
using namespace std;

struct StudentRecord
{
int studentNumber; // as ID
double quiz; // from input
double midterm; // from input
double final; // from input
double average; // calculated and output
char grade; // calculated and output
};

void input2(int index, StudentRecord students[]); // THIS IS MY PROBLEM, I AM CLUELESS ON HOW TO CREATE THE CORRECT DEFINITION FOR THIS, AND ALSO CORRECTLY CALLING IT, SO THE PROGRAM RUNS LIKE IT SHOULD.

//calculates the numeric average and letter grade.
void computeGrade(StudentRecord& student);

//outputs the student record.
void output(const StudentRecord& student);

int main()
{
const int CLASS_SIZE = 2;
StudentRecord studentAry[CLASS_SIZE];
int index;
cout << "Input " << CLASS_SIZE << " students' Data please...\n\n";
for(index = 0; index < CLASS_SIZE; index++)
{

input2(index, studentAry);

}
if (studentAry[index-1].studentNumber = studentAry[index].studentNumber)
cout << "Try another..." << endl;


for(index=0; index < CLASS_SIZE; index++)
computeGrade(studentAry[index]);

for(index=0; index < CLASS_SIZE; index++)
output(studentAry[index]);

system ("pause");
return 0;
}

void input2(int index, StudentRecord students[])

{
cout << "Enter the student number: ";
cin >> students[index].studentNumber;

cout << "Enter three grades of quiz, midterm, and final (Max 100 each): ";
cin >> students[index].quiz >> students[index].midterm >> students[index].final;
//if(students[2].studentNumber = students[1].studentNumber)
// cout << "This student's data has been entered already, please try another..." << endl;
}


void computeGrade(StudentRecord& student)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

student.average = (student.quiz + student. midterm + student.final)/3;

if (student.average < 60)
student.grade = 'F';
if (student.average < 70 && student.average >= 60)
student.grade = 'D';
if (student.average < 80 && student.average >= 70)
student.grade = 'C';
if (student.average < 90 && student.average >= 80)
student.grade = 'B';
if (student.average >= 90)
student.grade = 'A';
}

void output(const StudentRecord& student)
{
cout << "The record for student number: " << student.studentNumber << endl;
cout << "Three grades for quiz, midterm, and final are: ";
cout << student.quiz << " ";
cout << student.midterm << " ";
cout << student.final << endl;

cout << "The numeric average is: " << student.average << endl;
cout << "The letter grade assigned is: " << student.grade << endl;

}

Any suggestions or help will be greatly appreciated.
Topic archived. No new replies allowed.