| | |
please help me!!been trying to trace where ive gone wrong!!!
![]() |
•
•
Join Date: Jul 2006
Posts: 11
Reputation:
Solved Threads: 0
C Syntax (Toggle Plain Text)
#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);
Last edited by WolfPack; Jul 30th, 2006 at 10:19 am.
change this
to
this
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.
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])
)
{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])
)
{ Last edited by WolfPack; Jul 30th, 2006 at 10:42 am.
バルサミコ酢やっぱいらへんで
![]() |
Similar Threads
- building a bot (C++)
- Using Mid function and/or statement in IF (Visual Basic 4 / 5 / 6)
- help trendmicros housecall quarantine files (Viruses, Spyware and other Nasties)
- help me in my project to be submitted january 9, 2005 (C++)
- problem with tic-tac-toe! help. (C++)
- Help complete typical question with for loops (C++)
Other Threads in the C Forum
- Previous Thread: Ask a problem,About CEdit control
- Next Thread: Getting started in MFC, good links?
| Thread Tools | Search this Thread |
#include adobe api array arrays asterisks binarysearch calculate char cm copyanyfile copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile createprocess() csyntax database directory dynamic feet fflush fgets file fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o include incrementoperators input interest kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix meter microsoft motherboard mqqueue mysql number odf open opensource owf pattern pdf performance pointer posix probleminc process program programming pyramidusingturboccodes radix read recursion recv repetition research scanf scheduling segmentationfault send sequential shape socket socketprograming stack standard string systemcall turboc unix user voidmain() wab win32api windows.h






