what wrong with my code?i cannot compile

#include<string.h>
using namespace std;


class marks
{
private :
char name[50],grade;
float gpa;
public:
void marks::set_name(char n[50])
{
strcpy(name,n);
}

void marks::gpa(float g)
{
gpa = g;
}

void marks::set_grade(char gr,float g)
{
grade = gr;
if(3.00 <= g =< 4.00){
strcpy(grade,'A');
}

else if(2.00 <= g =< 2.99 ){
strcpy(grade.'B');
}

else if(0.00 <= g =< 1.99 ){
strcpt(grade,'F');
}
}


}

int main()
{
marks m;
char name[50],grade;
float gpa;


cout<<"==================================";
cout<<" enter info ";
cout<<"==================================";
cout<<"enter name : ";
cin.getline(name,50);
cout<<"enter cgpa : ";
cin>>gpa;

cout<<"==================================";
cout<<" result slip ";
cout<<"==================================";
cout<<"name : "<<name<<;
cout<<"GPA : "<<gpa<<;
cout<<"Grade : "<<grade<<;

m.set_name(name);
m.gpa(gpa);
m.set_grade();

}
closed account (Dy7SLyTq)
#include <iostream>
sry about that...actually i put already but mayb i forgot copy that to here...
Also it is #include <string> AFAIK
Also you should umm work on your class it looks completely wrong to me. I don't even see the closing brace to it or even the class object... all I see is public: then the "out of scope" declarations but you never initialize the functions inside the class or end the class.

Also please use code tags
[code][/code]
or the <> button ( on the right when submitting and the bottom when editting.

*edit
don't want to be mean or anything but you should read the error messages before posting =p
I'm sure you are getting an error with your class for starters you are missing the semi-colon at the end which your compiler will flag an error on.
1
2
3
4
5
class Something
{
public:
    Something();
};
Last edited on
closed account (Dy7SLyTq)
ok first of all you forgot the semi colon after the class def. secondly remove the marks:: on everything. its already in the scope of the class. thats what marks does so i cant remember if thats going to cause an error or its just redundant and finally you never gave grade an initial value which will def cause an error
kelvin0804 wrote:
what wrong with my code?i cannot compile


If you have compile errors - then post them here.

If you are going to use a C++ std::string then use one, instead of char arrays & strcpy functions.

1
2
3
4
5
6
7
8
9
10
11
char name[50];
char n[50];

strcpy(name,n);

std::string FirstName = "Fred";  // strings not char arrays
std::string LastName = "Astaire";

std::string FullName = FirstName + " " + LastName;  // instead of strcat

std::string CopyOfFullName = FullName;  //instead of strcpy 


Also, if you use an IDE, then chances are you can avoid simple syntax errors - it should show you them as you go along.

Hope all goes well.
Last edited on
closed account (Dy7SLyTq)
@glibit: string.h is not the same as string. string.h becomes cstring in c++
Topic archived. No new replies allowed.