a bit help

so i have this code that wouldn't run


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<iostream.h>
#include<conio.h>

class student{
public :
char name[20],sex;
};
class kid:public student{
private:
int age;
public:
kid(){}
kid (int a){age=a;}
void regist(int f){
if(f>5)cout<<"first grade";
else if (f==5)cout<<"level three";
else if(f==4)cout<<"level two";
else if (f==3)cout<<"level one";
else cout<<"too small";
};

void main(){
 kid K;
 int f;
 cout<<"enter the kids name";
cin>> K.name;
cout<<"enter his gender";
cin>>K.sex;
cout<<"age";
cin>>f;
kid *r();
  r=new kid();
  r->regist(f);
 getch();
}


could someone point out to me where i did wrong ?
What do you mean by "wouldn't run"? What behaviour are you seeing when you run it? What errors are you getting?
it wont work at all
i get :
lvalue required
pointer to structure required on left side of -> or ->*
declaration terminated incorrectly
Um, those don't look like runtime errors at all. They look like compilation errors, to me.

Could you please give us the full errors?
-compiling C:"The location basically"
!project2.cpp(32,1) lvalue required
!project2.cpp(33,1)pointer to structure required on left side of -> or ->*
!project2.cpp(36,1)declaration terminated incorrectly


is this what you mean ?
yea this wont compile.
for starters you're using cout with a std:: or having a using directive near the top of the file. (and you need to include iosteam and not iostream.h)

plus some other stuff.
we(our college) has never used iosteam what's the difference ?!
also whats up with my pointer ?!
Last edited on
At line 31, you're declaring a function called r, that returns a pointer to a kid. The compiler warning for line 32 indicates that you're trying to use a function name as a variable whose value can be set.

The compiler warning for line 33 is for much the same reason - you're trying to use a function name as a pointer variable.

http://members.gamedev.net/sicrane/articles/iostream.html

And i dont know if you even need to use a pointer for your kid.

@mutexe
you are probably right , the thing is it is a condition in the project + thanks for the link

so now i changed it a bit and the errors are now only
!project2.cpp(36,1)declaration terminated incorrectly

this is what i did
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void main(){
 kid K;
 int f;
 cout<<"enter the kids name";
cin>> K.name;
cout<<"enter his gender";
cin>>K.sex;
cout<<"age";
cin>>f;
kid *r;
  r= new kid();
  r->regist(f);
 getch();
}
The main function is supposed to return an int, indicating any error status. This allows the operating system to detect the exit status of the application.
Topic archived. No new replies allowed.