Thread: Seating Program

  1. #1
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942

    Seating Program

    The compiler says...

    initializer string for array of characters is too long---line 30
    non-|value in assignment---line 32
    parse error before string constant

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <fstream.h>
    
    #define MAX 6
    #define MAXLENGTH 8
    #define MAXDAYS 7
    #define DAYLENGTH 9
    
    void seatarrange();
    
    int main()
    {
          seatarrange();
          system("PAUSE");
          return 0;
    }
    void seatarrange()
    {
         int time;
         int turn;
         char seat[MAX][MAXLENGTH]={0};
         char day[MAXDAYS][DAYLENGTH]={
                                    "Monday" ,
                                    "Tuesday" ,
                                    "Wednesday" ,
                                    "Thursday" ,
                                    "Friday" ,
                                    "Saturday" ,
                                    "Sunday"};
         ofstream a_file("C:/Windows/Desktop/Seating.txt");
         for(turn=1 && time=1; turn <= MAX && time <= MAXDAYS; turn++)
         {
                     cout << "Who is in seat "<< turn << " on " << day[time-1] <<"?"
                          << endl;
                     cin >> seat[turn-1];
                     cout << "Seat " << turn << " on " << day[time-1] ": "
                          << seat[turn-1]
                          << endl;
                     a_file << "Seat " << turn << ": " << seat[turn-1] << "on day " << day[time-1] << endl;
          }
    }
    So what's up?

  2. #2
    Registered User
    Join Date
    Mar 2003
    Location
    UK
    Posts
    170
    > char day[MAXDAYS][DAYLENGTH]={

    DAYLENGTH is not long enought for "Wednesday" which is 10 including the string NULL terminator, add +1.
    Code:
     char day[MAXDAYS][DAYLENGTH+1]={
    > for(turn=1 && time=1; turn <= MAX && time <= MAXDAYS; turn++)

    change && to ,
    Code:
    for(turn=1 , time=1; turn <= MAX && time <= MAXDAYS; turn++)
    > cout << "Seat " << turn << " on " << day[time-1] ": "

    forgot one <<
    Code:
    cout << "Seat " << turn << " on " << day[time-1]  << ": "

  3. #3
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942

    doh!

    thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM