Hi guys ! I've made a program that marks a seat taken X in an airplane ..
So, here's what I've done.. it runs , but when i try to input other seat code, i.e., 1G, the no.2 in the grid becomes 88.. and I don't know how did that happen and how to fix it.. Please help me . Thanks . :)

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

   int x, y ;
   char s, z=1;

 struct grid {

      char upuan[5][5];
  }seats;

 void main(){

 clrscr();
 void GRID();
 void SEAT();

 GRID();
 SEAT();


  getch();}


  void SEAT(){
   int v;
   char chose[3];
   void display();
   printf("\n\nWhat seat?:\t");
   scanf("%s", chose);

   switch (chose[0]) {
      case '1': x=0;  break;
      case '2': x=1;  break;
      case '3': x=2;  break;
      case '4': x=3;  break;
      case '5': x=4;  break;
      case '6':break;
      case '7':break;

   }
   switch (chose[1]){
      case 'a':break;
      case 'A': y=1;  break;
      case 'b':break;
      case 'B': y=2; break;
      case 'c':break;
      case 'C': y=3; break;
      case 'd':break;
      case 'D': y=4; break;
      case 'e':break;
      case 'E':y=5; break;
      case 'f': break;
      case 'F':y=6; break;
      case 'g': break;
      case 'G':y=7; break;
      case 'h': break;
      case 'H':y=8;  break;
      case 'i': break;
      case 'I':y=9;  break;
      case 'j':break;
      case 'J':y=10;  break;
      case 'k': break;
      case 'K':y=11; break;
      case 'l': break;
      case 'L':y=12; break;
      case 'm': break;
      case 'M':y=13; break;
      case 'n': break;
      case 'N':y=14; break;
      case 'o':break;
      case 'O':y=15; break;
      case 'p': break;
      case 'P':y=16; break;
      case 'q': break;
      case 'Q':y=17; break;
      case 'r': break;
      case 'R':y=18; break;
      case 's': break;
      case 'S': y=19;    break;
      case 't':break;
      case 'T':y=20; break;
      case 'u': break;
      case 'U':y=21; break;
      case 'v': break;
      case 'V':y=22; break;
      case 'w': break;
      case 'W':y=23;  break;
      case 'x': break;
      case 'X':y=24; break;
      case 'y':break;
      case 'Y':y=25; break;
      case 'z':break;
      case 'Z':y=26; break;
}


if  (seats.upuan[x][y]!='X')
	    { seats.upuan[x][y]='X';
	      }
	 else   {
	     printf("Seat Taken!");
	     SEAT(); }
     display();

	printf("\n\nWould you like to select again? 1-yes 0-no ");
 scanf("%d", &v);
   if (v==1)
    SEAT();



	}



  void GRID() {
 int col=27;
 int row=2;
   for(x=0; x<=4; x++){
     s='A';
     for (y=0,col=27; y<=4; y++){
       if (y==0){
	 seats.upuan[x][y]=z;
	 gotoxy(col,row);
	 printf("%d\t", seats.upuan[x][y]);

	 }
       else {
	 seats.upuan[x][y]=s;
	  gotoxy(col,row);
	  printf("%c\t", seats.upuan[x][y]);
	  s++; }
	  col+=5;
	  }
	 row+=2;
     z++; }   }


void display()
 { int a, b, col=27, row=2;
   clrscr();
 for(a=0; a<=4; a++){

     for (b=0,col=27; b<=4; b++){
       if (b==0){

	 gotoxy(col,row);
	 printf("%d\t", seats.upuan[a][b]);

	 }
       else {

	  gotoxy(col,row);
	  printf("%c\t", seats.upuan[a][b]);
	  }
	  col+=5;
	  }
	 row+=2;
}	}

Ah .. I just missed to put default .. My problem is solved already .. :)

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

   int x, y ;
   char s, z=1;

 struct grid {

      char upuan[5][5];
  }seats;

 void main(){

 clrscr();
 void GRID();
 void SEAT();

 GRID();
 SEAT();


  getch();}


  void SEAT(){
   int v;
   char chose[3];
   void display();
   printf("\n\nWhat seat?:\t");
   scanf("%s", chose);

   switch (chose[0]) {
      case '1': x=0;  break;
      case '2': x=1;  break;
      case '3': x=2;  break;
      case '4': x=3;  break;
      case '5': x=4;  break;
default: { 
		printf("Invalid Input");}

   }
   switch (chose[1]){
      case 'a':
      case 'A': y=1;  break;
      case 'b':
      case 'B': y=2; break;
      case 'c':
      case 'C': y=3; break;
      case 'd':
      case 'D': y=4; break;
      default: {
		 printf("Invalid Input"); SEAT(); }
      }


	 if  (seats.upuan[x][y]!='X')
	    { seats.upuan[x][y]='X';
	      }
	 else   {
	     printf("Seat Taken!");
	     SEAT(); }
     display();

	printf("\n\nWould you like to select again? 1-yes 0-no ");
 scanf("%d", &v);
   if (v==1)         {
    SEAT();           }
    else if(v==0){
	exit(0);  }
     else          {
     printf("\n\n\t\tInvalid Input!\n\n\t\tPROGRAM TERMINATED.");

       getch();
		    }


	}



  void GRID() {
 int col=27;
 int row=2;
   for(x=0; x<=4; x++){
     s='A';
     for (y=0,col=27; y<=4; y++){
       if (y==0){
	 seats.upuan[x][y]=z;
	 gotoxy(col,row);
	 printf("%d\t", seats.upuan[x][y]);

	 }
       else {
	 seats.upuan[x][y]=s;
	  gotoxy(col,row);
	  printf("%c\t", seats.upuan[x][y]);
	  s++; }
	  col+=5;
	  }
	 row+=2;
     z++; }   }


void display()
 { int a, b, col=27, row=2;
   clrscr();
 for(a=0; a<=4; a++){

     for (b=0,col=27; b<=4; b++){
       if (b==0){

	 gotoxy(col,row);
	 printf("%d\t", seats.upuan[a][b]);

	 }
       else {

	  gotoxy(col,row);
	  printf("%c\t", seats.upuan[a][b]);
	  }
	  col+=5;
	  }
	 row+=2;
}	}

If you started the thread, there should be a "Mark as Solved" link below the last post.
though its ok if you don't really wanna mark this one as solved since me and the other member would get a +1 solved thread without actually helping you... but hey that's up to you :)

If you started the thread, there should be a "Mark as Solved" link below the last post.

read my last post

This article has been dead for over six months. Start a new discussion instead.