954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

please help me!!been trying to trace where ive gone wrong!!!

#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[i] = 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[i], last[i], seats[i], destination[i], amount[i], confirmed[i]);
fclose(outp);
printf("Thank You..");
break;
default: printf("Wrong Choice\n\n");
}
}while(choice != 5);
priya123
Newbie Poster
11 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

What is your problem?

WolfPack
Postaholic
Moderator
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
 

im getting 2 errors in the lines:for(int status = fscanf(inp, "%s", first[n]);and status != EOF;

priya123
Newbie Poster
11 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

help meeee....

priya123
Newbie Poster
11 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

That is what I am trying to do. The least you can do is quit whining.

WolfPack
Postaholic
Moderator
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
 

Are you compiling this as C or C++?

WolfPack
Postaholic
Moderator
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
 

my program is not getting executed!!there is a problem in the lines i mentioned above.can u please rectify!!!
pria

priya123
Newbie Poster
11 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

am compiling it in turboc.could u trace anything???

priya123
Newbie Poster
11 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

change this

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[i] = 0;
    n = 0;
    
    for
    (
        int status = fscanf(inp, "%s", first[n]);
        status != EOF;
        status = fscanf(inp, "%s", first[n])
    )
    {


to
this

FILE *inp, *outp;
    int status;
    inp = fopen("E:reservat.txt", "r");
    if(inp == NULL)
    {
        printf("Cannot open the file ");
        exit(1);
    }
    for(i = 0; i < MAX; i++)
        reserved[i] = 0;
    n = 0;
    for
    (
        status = fscanf(inp, "%s", first[n]);
        status != EOF;
        status = fscanf(inp, "%s", first[n])
    )
    {


The reason is you can't declare variables everywhere in C like in C++. All the variables in C must be declared at the beginning of a block before any other C statements.

WolfPack
Postaholic
Moderator
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
 

hey sorry to disturb you!!i have to submit my assignment 2moro!!so im lil tensed...did u trace where ive gone wrong????

priya123
Newbie Poster
11 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

*rolleyes*

WolfPack
Postaholic
Moderator
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
 

hey thank you very much!but again i faced a warning at the end....which says function should return a value in the last line
while(choice != 5);

priya123
Newbie Poster
11 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

Well you could help yourself by telling us which actual error messages you see.

> am compiling it in turboc
Ah, good old stone age technology - have you sharpened the stone chisel recently?

I'm also guessing you don't know the answer to the question "are you compiling C or C++" either. Sure it looks mostly like C, but that really depends on whether you called your file prog.c or prog.cpp.
Or whether you've passed any other options to the compiler to tell it which language to assume.

> for(int status =
C only got this kind of declaration in the C99 standard, which your compiler predates by decades, so it isn't going to support it.
I don't recall when C++ allowed this either, but I'd guess your fossil compiler won't even understand this in C++ mode either.

Declare the int at the start of the block (like you do for all your other variables) and see how you get on with that.

Now get a decent compiler (one made for this millenium) and leave turbo-c to the archaeology students.
http://www.compilers.net/Dir/Free/Compilers/CCpp.htm
Borland 5.5, Dev-C++, Digital Mars, MinGW, Microsoft Visual C++ express would all be a big step forward.

Late, but nevermind....

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

and could u please tell me what are these linker errors!im unable to get the output.

priya123
Newbie Poster
11 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

yea am getting a warning at the end which says that function should return a value.
in the last line }
and thank you.will download the new compiler...

priya123
Newbie Poster
11 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

Linker errors - I see no linker errors.
Try and think ahead when you post, anticipate what people are going to ask in response to content-free one-line posts.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

> and thank you.will download the new compiler...
I think I would save that until tomorrow. It's not a good idea to change this close to the deadline. Get it out of the way, then you'll have plenty of time to install and get used to it.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

there is a warning!!could u please help me...in the last statement im getting a warning which says function should return a value????

priya123
Newbie Poster
11 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

there is a warning.can u please tell me...

priya123
Newbie Poster
11 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

How to ask a question about code:Learn to use indentation.
Post the whole code that is your latest attempt.
Use code tags.
If there are error or warning messages, copy and paste them into the post.
Ask the question, state what confuses you, etc.
None of your attempts yet fit that mold, so it should come as no surprise that you do not yet have an answer. Had you followed this procedure your question would probably have been answered already.

The following is an example of a useless post:there is a warning.can u please tell me...

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You