Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,487 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,709 people online right now. Registration is fast and FREE... Join Now!




Compilation error

 
Reply to this topicStart new topic

Compilation error

naash
5 Mar, 2008 - 06:25 PM
Post #1

D.I.C Head
**

Joined: 25 Aug, 2007
Posts: 77


My Contributions
It gives following 2 compilation errors :

1 Declaration missing ;
2 expected {

The code gives where !

CODE

#include<stdio.h>
#include<conio.h>

struct passenger
{
  char name[10];
  int age;
  int isempty=0;        // Declaration missing;
}s[65];

void main()
{
  int total,rows,flag,n,left;
  char ch='y';
  while(ch=='y')
  {
    total=65;
    rows=flag=left=0;
    printf("\nEnter how many seats : ");
    scanf("%d",n);
    while(rows<=13)
     {
     left=5-flag%5;
     if(n<=left)
       {
        allot(s,n,&total,&rows);
        flag+=n;
       }
     else
     {
        rows++;
        allot(s,n,&total,&rows);
        flag+=n;
     }
    }
    printf("\nPress y else any");
   ch=getch();
   }
}

void allot(struct *s,int n,int *total,int *rows)  // expected  {
{
  char NAME[10];
  int AGE,i;
  int loc=find(n);
    if(loc==-1)
    {
    allot(s,n-1,&total,&rows); //to distribute the seats into n-1 and 1 combination
    allot(s,1,&total,&rows);
    return;
    }
  for(i=0;i<n;i++)
  {
    printf("\nNAME : ");
    scanf("%s",NAME);
    printf("\nAGE : ");
    scanf("%d",AGE);
    s[loc+i].name=NAME;
    s[loc+i].age=AGE;
    s[loc+i].isempty=1;
    total--;
    if(total%5==0)
       rows++;
  }
}

//this fucntion find if there are num number of
//consecutive seats and if yes then returns the index
//from where they start;

int find(int num)
{
  int num1=num,i;
  for(i=0;i<65;i++)
    {
    if((i+1)%5==0)
    {
      num1=num;
      continue;
    }
    if(num1==0)
    break;
    if(s[i].isempty==0)
    num1--;
    else
    num1=num;
    }
  if(num1!=0)
    return -1;
  else
    return i-num1;
}

User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Compilation Error
5 Mar, 2008 - 06:31 PM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,465



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
I don't see where you declared the function allot.
User is online!Profile CardPM
+Quote Post

MorphiusFaydal
RE: Compilation Error
5 Mar, 2008 - 06:49 PM
Post #3

D.I.C Lover
Group Icon

Joined: 12 May, 2005
Posts: 1,105



Thanked: 8 times
Expert In: Hardware, Networking

My Contributions
QUOTE(no2pencil @ 5 Mar, 2008 - 08:31 PM) *

I don't see where you declared the function allot.


It's right below main()
User is offlineProfile CardPM
+Quote Post

naash
RE: Compilation Error
6 Mar, 2008 - 07:06 AM
Post #4

D.I.C Head
**

Joined: 25 Aug, 2007
Posts: 77


My Contributions
QUOTE(MorphiusFaydal @ 5 Mar, 2008 - 07:49 PM) *

QUOTE(no2pencil @ 5 Mar, 2008 - 08:31 PM) *

I don't see where you declared the function allot.


It's right below main()


What ???
At least gimme a solution !
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Compilation Error
6 Mar, 2008 - 08:11 AM
Post #5

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 39 times
Dream Kudos: 25
My Contributions
The declaration missing error in your struct definition is occurring because you are trying to assign a value of 0 to the data member isempty for all 65 instances. It should look like:
CODE

struct passenger
{
  char name[10];
  int age;
  int isempty;
}s[65];


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 07:28PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month