help in c++

Status
Not open for further replies.

nirvanasoul

Inactive
Contributor
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class name
{
char nam[5];
public:
void input()
{
cout<<"Enter your name ";
gets(nam);
}
void show()
{
cout<<nam;
}
void main()
{
clrscr();
name b1;
b1.input();
b1.show();
getch();
}
}
Error: "deceleration terminated incorrectly"!

Help me

thankx in adv...
 
are you sure you want to put that main function inside the name class ??
Take it out of the class and then recompile.
 
here's corrected program -

Code:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class name           //class declaration
{
 char nam[5];
  public:
  void input()
  {
  cout<<"Enter your name ";
  gets(nam);
  }
  void show()
  {
  cout<<nam;
  }
[B]};                    //end of class[/B]

void main()            //separate main function, you had written it within class, which is syntactically wrong
{
  clrscr();
  name b1;
  b1.input();
  b1.show();
  getch();
}

You just ended the class incorrectly i.e.

class name
{
.
.
.
} (you forgot semicolon here i.e. }; )

and included main function into class.
 
Status
Not open for further replies.