Hi guys,
A good day to you all!
I am trying to bulid a simple data base but two errors at compile time apparently are
holding me back from running my program. I have tried to figure them out but my efforts are are proving worthless and that's why am turning to you guys right here.
The first error is a "declaration syntax error"
The second says"declaration is not allowed here".
I did try to check out the help menu and the suggestions just couldn't work out.I am using borland c++ 5.02

void main(void)
{
 char invite;
printf("^^^^^^^^^^YOSSARIAN'S CAR RENTAL^^^^^^^^^^\n");
printf("Hi,please Welcome!\n");
printf("To proceed,please press C, to quit hit X:\n");
scanf("%c",&invite);
 if(invite=='c')
mainmenu();
 else
{
printf("Thank you for visiting!");
getch();
}
void mainmenu(void)///this is where it says declaration not allowed
{/////this is where it indicates syntax declaration error
char choice;
while(choice)
{
clrscr();

printf("\n\t\t*****************************");
printf("\n\t\tStudent Administration System" );
printf("\n\t\t         Main Menu");
printf("\n\t\t*****************************\n");
printf("\n\t\tA.Add customer details");
printf("\n\t\tB.View customer records");
printf("\n\t\tC.Search for customer records");
printf("\n\t\tD.Modify customer records");
printf("\n\t\tE.Delete Customer details");
printf("\n\t\tF.Exit the system!");
printf("\n");
printf("\n\t\t*****************************\n");
printf("\n\t\t Enter Your Choice [1 - 6]:  ");
//printf("\n\t\t*****************************");
scanf("%c", &choice);



switch(choice)
{
char category;
case 'A':
 printf("For tourist select T, L for loyalty or O for others:\n");
  category==getchar();
  if(getchar()=='T'||'t')
  addcustomer_rec();
  else if(getchar()=='L'||'l')
  addcustomer_rec();
  else if(getchar()=='O'||'o')
  addcustomer_rec();
  else printf("End of the road!");
break;

There are three categories of customers in a structure of which I create a function so as to accept customer details without having to rewrite the same code for @ category e.g name.tourist,name.loyal and name.others
e.g function: cus_details(struct customer loyal,tourist,others)
To enter these details I would have to write something like,
printf("Enter first name:");
scanf("%c",f_name.loyal)///what would I have to do so to write a function that can enter details automatically for all the three categories?

Cheers everbody!

what is the matter with this code?

For one, it's a bad title for a thread.
For two, no CODE Tags.
For three, bad formatting.
Four, old code practices from the 1980's.

First things first.
1) Read the Member Rules. Make an effective title for your thread.
2) Code Tags are described all over the site. Find them. Read them.
3 & 4) See this, this, this, and this.

The first error is a "declaration syntax error"

Given 53 lines, does this error as it is make sense?

The second says"declaration is not allowed here".

Where's here? If you were given this information -- and only this information -- what could you do with it?

commented: 4 excellent points +17

Hi there again,
Excuse for where I went wrong. I do acknowledge my shortcomings.
I put those errors in quotes because I just wanted to give them to you as they appear.They were not meant to be used as an indicator to something.When you look at the code, there are areas where I indicated the cause of the errors.
Thanks for you responses!

The statements starting on line 46 are not constructed correctly. if( category == 'T' || category == 't') You don't want to call getchar() inside each of those if statements. Its already called on line 45 so all you have to do is use the value of category.

After EVERY scanf("%c...), when you are storing a char data type, add this:

getchar();

Right after it. OK, the last one in the whole program, you don't need to add this line of code.

What it does is remove the newline char that scanf() always leaves behind in the input stream (unless you use a special format).

This is THE most common problem for new students, in C. (Until they learn pointers) ;)

Lines 8-10: Something is wrong before and after "mainmenu();". Go figure. :p

::
scanf("%c",&invite);
if(invite=='c')
mainmenu();
else
{
::

Hi my dear,

FIRST:

At 15th line you should close the main function, then you have to proceed your implementation for mainmenu() function.

With this you won't get error at 15th line.


SECOND:

"EVERY FUNCTION IN C RETURNS int BY DEFAULT".

You are making a call to mainmenu() in 9 and you are implementing it in 15th line, there you should use int instead of void as return type
(or)
declare mainmenu() as void meainmenu(void); before the main() function.


Make those changes and check it out. Surely it will work.

BYE

Hi, you have called the function like mainmenu() without declaration. C treats that as int mainmenu(void); But in the function definition you written void mainmenu(void). Obviously this function wouldn't be called. SO declaration violation occured. Means the function which you have called has no declaration. As per the rules each function must be declared before going to be called. I think you will be happy with this solution.

Declare mainmenu() function with header file..:):):)

#include *
void mainmenu(void);

It starts working....sure..:):):)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.