A
Alami
I'm newdie in c programming. this is my first project in programming.
I have to write a program for a airline reservation. this is what i
have done yet. but when it runs it shows the number of seats as 0 and
the flight no. is also repeating. If any can tell why is this please
help me.
#include<stdio.h>
#include<ctype.h>
#include<conio.h>
#include<memory.h>
#include<iostream.h>
void reserv(), add(), view();
void main()
{
short choice1;
clrscr();
gotoxy(5,5);
printf("\t\t\tASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t\t----------------------------------\n");
printf("\n");
printf("\t\t Main Menue\n");
printf("\n\n");
gotoxy(10,10);
printf("1. Reservation\n");
gotoxy(10,12);
printf("2. Flight List\n");
gotoxy(10,14);
printf("3. Help\n");
gotoxy(10,16);
printf("4. Exit\n");
printf("\n\n\n");
gotoxy(10,20);
printf("Enter ur choice: ");
scanf("%i",&choice1);
printf("\n");
printf("\n");
printf("\n");
switch(choice1) {
case 1:
reserv();
break;
case 2:
printf("Flight List\n");
break;
case 3:
printf("Helping window\n");
break;
case 4:
printf("Exit from the window\n");
break;
default:
printf("Invalid\n");
getch();
}
}
/*------------------------------
reservation---------------------------------*/
void reserv()
{
short choice2;
clrscr();
gotoxy(5,3);
printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
printf("\n");
printf("\t\t Reservation\n");
gotoxy(10,10);
printf("1. Booking a seat\n");
gotoxy(10,12);
printf("2. Edit details\n");
gotoxy(10,14);
printf("3. View Details\n");
gotoxy(10,16);
printf("4. Cancel Reservation\n");
gotoxy(10,18);
printf("5. Search Details\n");
gotoxy(10,20);
printf("6. Exit\n");
printf("\n\n\n");
gotoxy(10,22);
printf("Enter ur choice: ");
scanf("%i",&choice2);
printf("\n");
printf("\n");
printf("\n");
switch(choice2) {
case 1:
add(); /*----------add reservation-----------*/
break;
case 2:
printf("Edit name\n"); /*-----------edit reservation---------*/
break;
case 3:
view(); /*-----------view reservation----------*/
break;
case 4:
printf("Delete"); /*------------delete reservation---------*/
break;
case 5:
printf("Search \n"); /*------------search reservation----------
*/
break;
case 6:
printf("Exit from the window\n");
break;
default:
printf("invalid\n");
}
}
/*-------------------------------
Add-----------------------------------------*/
void add()
{
char name[40];
int res_num=0,up;
int seat;
char flight[6];
char pass[8];
FILE*sfile;
if((sfile=fopen("c:\\air.dat","a+"))==NULL)
res_num=1;
else { do{ fscanf(sfile,"%i\t %s \t\t%s \t%i \t%s",&res_num,&name,&pass,&seat,
&flight);
}while(!feof(sfile));
res_num+=1;
}
clrscr();
gotoxy(5,3);
printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
gotoxy(25,6);
printf("Booking a seat");
printf("\n\n\n\n");
printf("Reservation no: %04i ",res_num);
printf("\nName : ");
fflush(stdin);
gets(name);
printf("passport no : ");
fflush(stdin);
gets(pass);
printf("number of seats: ");
scanf("%i",&seat);
printf("flight : ");
fflush(stdin);
gets(flight);
printf("\n\n Record Saved!");
fprintf(sfile,"%i \t%s \t\t%s \t%i \t%s\n",res_num,name,pass,seat,flight);
fclose(sfile);
do{ printf("\nPress [2] to go to reservation: ");
scanf("%i",&up);
if(up!=2)
printf("Invalid Entry");
}while(up!=2);
reserv();
}
/*-----------------------view
reservations------------------------------------*/
void view(void)
{
char name[40];
int res_num,up;
int seat;
char flight[6];
char parse[8];
FILE*sfile;
clrscr();
if((sfile=fopen("c:\\air.dat","a+"))==NULL)
printf("File Empty!");
else { printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
printf("\n\n No Name\t\t NRIC \t No.of seats \t Flight\n");
printf("-------------------------------------------------\n");
while(!feof(sfile)) { fscanf(sfile,
"%04i \t%s \t\t%s \t%i \t%s",&res_num,&name,&parse,&seat,&flight);
if(feof(sfile))
break;
printf("%04i \t%s \t\t%s \t%i \t%s\n",res_num,name,parse,seat,flight);
}
}
fclose(sfile);
do{ printf("\n\n\nPress [2] to go to reservation: ");
scanf("%i",&up);
if(up!=2)
printf("Invalid Entry");
}while(up!=2);
reserv();
}
I think my problem is in add and view functions.
Please help me.
I have to write a program for a airline reservation. this is what i
have done yet. but when it runs it shows the number of seats as 0 and
the flight no. is also repeating. If any can tell why is this please
help me.
#include<stdio.h>
#include<ctype.h>
#include<conio.h>
#include<memory.h>
#include<iostream.h>
void reserv(), add(), view();
void main()
{
short choice1;
clrscr();
gotoxy(5,5);
printf("\t\t\tASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t\t----------------------------------\n");
printf("\n");
printf("\t\t Main Menue\n");
printf("\n\n");
gotoxy(10,10);
printf("1. Reservation\n");
gotoxy(10,12);
printf("2. Flight List\n");
gotoxy(10,14);
printf("3. Help\n");
gotoxy(10,16);
printf("4. Exit\n");
printf("\n\n\n");
gotoxy(10,20);
printf("Enter ur choice: ");
scanf("%i",&choice1);
printf("\n");
printf("\n");
printf("\n");
switch(choice1) {
case 1:
reserv();
break;
case 2:
printf("Flight List\n");
break;
case 3:
printf("Helping window\n");
break;
case 4:
printf("Exit from the window\n");
break;
default:
printf("Invalid\n");
getch();
}
}
/*------------------------------
reservation---------------------------------*/
void reserv()
{
short choice2;
clrscr();
gotoxy(5,3);
printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
printf("\n");
printf("\t\t Reservation\n");
gotoxy(10,10);
printf("1. Booking a seat\n");
gotoxy(10,12);
printf("2. Edit details\n");
gotoxy(10,14);
printf("3. View Details\n");
gotoxy(10,16);
printf("4. Cancel Reservation\n");
gotoxy(10,18);
printf("5. Search Details\n");
gotoxy(10,20);
printf("6. Exit\n");
printf("\n\n\n");
gotoxy(10,22);
printf("Enter ur choice: ");
scanf("%i",&choice2);
printf("\n");
printf("\n");
printf("\n");
switch(choice2) {
case 1:
add(); /*----------add reservation-----------*/
break;
case 2:
printf("Edit name\n"); /*-----------edit reservation---------*/
break;
case 3:
view(); /*-----------view reservation----------*/
break;
case 4:
printf("Delete"); /*------------delete reservation---------*/
break;
case 5:
printf("Search \n"); /*------------search reservation----------
*/
break;
case 6:
printf("Exit from the window\n");
break;
default:
printf("invalid\n");
}
}
/*-------------------------------
Add-----------------------------------------*/
void add()
{
char name[40];
int res_num=0,up;
int seat;
char flight[6];
char pass[8];
FILE*sfile;
if((sfile=fopen("c:\\air.dat","a+"))==NULL)
res_num=1;
else { do{ fscanf(sfile,"%i\t %s \t\t%s \t%i \t%s",&res_num,&name,&pass,&seat,
&flight);
}while(!feof(sfile));
res_num+=1;
}
clrscr();
gotoxy(5,3);
printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
gotoxy(25,6);
printf("Booking a seat");
printf("\n\n\n\n");
printf("Reservation no: %04i ",res_num);
printf("\nName : ");
fflush(stdin);
gets(name);
printf("passport no : ");
fflush(stdin);
gets(pass);
printf("number of seats: ");
scanf("%i",&seat);
printf("flight : ");
fflush(stdin);
gets(flight);
printf("\n\n Record Saved!");
fprintf(sfile,"%i \t%s \t\t%s \t%i \t%s\n",res_num,name,pass,seat,flight);
fclose(sfile);
do{ printf("\nPress [2] to go to reservation: ");
scanf("%i",&up);
if(up!=2)
printf("Invalid Entry");
}while(up!=2);
reserv();
}
/*-----------------------view
reservations------------------------------------*/
void view(void)
{
char name[40];
int res_num,up;
int seat;
char flight[6];
char parse[8];
FILE*sfile;
clrscr();
if((sfile=fopen("c:\\air.dat","a+"))==NULL)
printf("File Empty!");
else { printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
printf("\n\n No Name\t\t NRIC \t No.of seats \t Flight\n");
printf("-------------------------------------------------\n");
while(!feof(sfile)) { fscanf(sfile,
"%04i \t%s \t\t%s \t%i \t%s",&res_num,&name,&parse,&seat,&flight);
if(feof(sfile))
break;
printf("%04i \t%s \t\t%s \t%i \t%s\n",res_num,name,parse,seat,flight);
}
}
fclose(sfile);
do{ printf("\n\n\nPress [2] to go to reservation: ");
scanf("%i",&up);
if(up!=2)
printf("Invalid Entry");
}while(up!=2);
reserv();
}
I think my problem is in add and view functions.
Please help me.