#include<stdio.h>
#include<stdlib.h>
#define MAX 30
int menu(){
int choice;
printf("1. Add a new reservation\n");
printf("2. Show details of a reservation (given reservation number)\n");
printf("3. Make Payment (given the reservation number and payment amount)\n");
printf("4. Confirm a Reservation (given the reservation number)\n");
printf("5. Quit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
return(choice);
}
int GetReservationNumber(){
int PNR;
do{
printf("Enter reservation number: ");
scanf("%d", &PNR);
if(PNR < 0)
printf("Wrong number\n");
}while(PNR < 0);
return(PNR);
}

void DisplayInfo(char first[][15], char last[][15], int seats[], char destination[][15], float amount[], int confirmed[], int PNR){
printf("\nNAME : %s %s\n", first[PNR], last[PNR]);
printf("# SEATS : %d\n", seats[PNR]);
printf("DESTINATION: %s\n", destination[PNR]);
printf("AMOUNT : %.3f SAR\n", amount[PNR]);
if(confirmed[PNR] == 1)
printf("STATUS : CONFIRMED\n\n");
else
printf("STATUS : UNCONFIRMED\n\n");
}
void AddNew(char first[][15], char last[][15], int seats[], char destination[][15], int n){
printf("Enter first name: ");
scanf("%s", first[n]);
printf("Enter last name: ");
scanf("%s", last[n]);
do{
printf("Enter number of seats: ");
scanf("%d", &seats[n]);
if(seats[n] <= 0)
printf("Wrong number\n");
}while(seats[n] <= 0);
printf("Enter destination: ");
scanf("%s", destination[n]);
}
void GetAmount(float amount[], int PNR){
do{
printf("Enter the amount in SAR: ");
scanf("%f", &amount[PNR]);
if(amount[PNR] <= 0)
printf("Wrong amount\n");
else
printf("Thank you\n\n");
}while(amount[PNR] <= 0);
}
main(){
int seats[MAX], confirmed[MAX], n, reserved[MAX], i, PNR, choice;
float amount[MAX];
char first[MAX][15], last[MAX][15], destination[MAX][15];
FILE *inp, *outp;
inp = fopen("E:reservat.txt", "r");
if(inp == NULL){
printf("Cannot open the file ");
exit(1);
}
for(i = 0; i < MAX; i++)
reserved = 0;
n = 0;
for(int status = fscanf(inp, "%s", first[n]);
status != EOF;
status = fscanf(inp, "%s", first[n])){
fscanf(inp, "%s%d%s%f%d", last[n], &seats[n], destination[n], &amount[n], &confirmed[n]);
reserved[n] = 1;
n++;
}
fclose(inp);
do{
choice = menu();
switch(choice){
case 1: if(n < MAX){
AddNew(first, last, seats, destination, n);
reserved[n] = 1;
printf("Thank You, your reservation number is %d (Unconfirmed)\n\n", n);
n++;
}else
printf("The arrays are full\n\n");
break;
case 2: PNR = GetReservationNumber();
if(reserved[PNR] == 1)
DisplayInfo(first, last, seats, destination, amount, confirmed, PNR);
else
printf("Not Found\n\n");
break;
case 3: PNR = GetReservationNumber();
if(reserved[PNR] == 1)
GetAmount(amount, PNR);
else
printf("Not Found\n\n");
break;
case 4: PNR = GetReservationNumber();
if(reserved[PNR] == 1){
confirmed[PNR] = 1;
printf("The reservation is confirmed\n\n");
}else
printf("Not Found\n\n");
break;
case 5: outp = fopen("a:reservation.txt", "w");
for(i = 0; i < n; i++)
fprintf(outp, "%s %s %d %s %.3f %d\n", first, last, seats, destination, amount, confirmed);
fclose(outp);
printf("Thank You..");
break;
default: printf("Wrong Choice\n\n");
}
}while(choice != 5);
}

as u guys see at above. when i create my c++ project and run it. the command line will say cannot open file.press any key to continue. what i have to put in the fopen?

what i have to put in the fopen?

i think you need a '/' something line "e:/reservat.txt"

This is more of a C code though and please read about 'code-tags'.

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.