C ++ programming here my codes

S

sscolon

# include <iostream>

using std::cout;
using std::cin;
using std::endl;

enum GradeType {A, B, C, D, F};
struct StudentRec
{

string firstName;
string lastName;
float average;
int grade;
int finalExam;
GradeType courseGrade;
};
int main
{
StudentRec FirstStudent;
StudentRec student;
int grade


cout << " Enter your First Name:" << endl;
cin >> firstName;

cout << "Enter your percentage:" << endl;
cin >>percentage;

cout << " name " << " score " << " Final Grade " << endl;

cin >> student.finalExam;
grade = student.finalExam + studentGrade;

if (grade >=90)
student.courseGrade = A;
else if (grade >=80)
student.courseGrade = B;

else if (grade >= 70)
student.courseGrade = D;

else if (grade>= 60)
student.courseGrade = C;

else

cout << grade << "F" << endl;


return 0;
}

I am sorry, I forget to write my codes. But it does not work.

Sandra
 
R

Rolf Magnus

Please write postings that belong to other postings as replies to those
postings. It's rather cumbersome to find out what you're talking about.

# include <iostream>

using std::cout;
using std::cin;
using std::endl;

enum GradeType {A, B, C, D, F};
struct StudentRec
{

string firstName;
string lastName;
float average;
int grade;
int finalExam;
GradeType courseGrade;
};
int main
{
StudentRec FirstStudent;
StudentRec student;
int grade
cout << " Enter your First Name:" << endl;
cin >> firstName;

cout << "Enter your percentage:" << endl;
cin >>percentage;

cout << " name " << " score " << " Final Grade " << endl;

cin >> student.finalExam;
grade = student.finalExam + studentGrade;

if (grade >=90)
student.courseGrade = A;
else if (grade >=80)
student.courseGrade = B;

else if (grade >= 70)
student.courseGrade = D;

else if (grade>= 60)
student.courseGrade = C;

else

cout << grade << "F" << endl;


return 0;
}

I am sorry, I forget to write my codes. But it does not work.

"does not work" isn't a very good description. How does it not work?
Doesn't it do what you expected? What does it do instead? Does it not
compile or link? What error message did you get? In which line?
 
D

David White

You didn't say what's wrong or what help you want, so I'm just guessing that you want to know
what's wrong with your code.
# include <iostream>

Also:
#include said:
using std::cout;
using std::cin;
using std::endl;

Also:
using std::string;
enum GradeType {A, B, C, D, F};
struct StudentRec
{

string firstName;
string lastName;
float average;
int grade;
int finalExam;
GradeType courseGrade;
};
int main

Should be: int main()
{
StudentRec FirstStudent;

You are not using FirstStudent anywhere.
StudentRec student;
int grade

Should be: int grade;
cout << " Enter your First Name:" << endl;
cin >> firstName;

You have not defined a variable 'firstName'. Did you mean student.firstName?
cout << "Enter your percentage:" << endl;
cin >>percentage;

You have not defined a variable 'percentage'. All variables you use have to be defined somewhere
first.
cout << " name " << " score " << " Final Grade " << endl;

cin >> student.finalExam;
grade = student.finalExam + studentGrade;

You have not defined a variable 'studentGrade'.
if (grade >=90)
student.courseGrade = A;
else if (grade >=80)
student.courseGrade = B;

else if (grade >= 70)
student.courseGrade = D;

else if (grade>= 60)
student.courseGrade = C;

else

cout << grade << "F" << endl;


return 0;
}

Also, to make it work as you described earlier, you will need a collection of StudentRecs (e.g.,
a std::vector<StudentRec>) and you will need a loop in your code (a 'do' or a 'while') so that
the program will keep asking for details of more students until the exit value is entered. But
you can add that later. Get the code working for one student first.

If you have more questions, reply to a post in this thread instead of starting a new one. All
posts relating to the same problem should be together.

DW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top