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

Reply

Join Date: Jul 2006
Posts: 11
Reputation: priya123 is an unknown quantity at this point 
Solved Threads: 0
priya123 priya123 is offline Offline
Newbie Poster

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

 
0
  #1
Jul 30th, 2006
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #define MAX 30
  4. int menu(){
  5. int choice;
  6. printf("1. Add a new reservation\n");
  7. printf("2. Show details of a reservation (given reservation number)\n");
  8. printf("3. Make Payment (given the reservation number and payment amount)\n");
  9. printf("4. Confirm a Reservation (given the reservation number)\n");
  10. printf("5. Quit\n");
  11. printf("Enter your choice: ");
  12. scanf("%d", &choice);
  13. return(choice);
  14. }
  15. int GetReservationNumber(){
  16. int PNR;
  17. do{
  18. printf("Enter reservation number: ");
  19. scanf("%d", &PNR);
  20. if(PNR < 0)
  21. printf("Wrong number\n");
  22. }while(PNR < 0);
  23. return(PNR);
  24. }
  25.  
  26. void DisplayInfo(char first[][15], char last[][15], int seats[], char destination[][15], float amount[], int confirmed[], int PNR){
  27. printf("\nNAME : %s %s\n", first[PNR], last[PNR]);
  28. printf("# SEATS : %d\n", seats[PNR]);
  29. printf("DESTINATION: %s\n", destination[PNR]);
  30. printf("AMOUNT : %.3f SAR\n", amount[PNR]);
  31. if(confirmed[PNR] == 1)
  32. printf("STATUS : CONFIRMED\n\n");
  33. else
  34. printf("STATUS : UNCONFIRMED\n\n");
  35. }
  36. void AddNew(char first[][15], char last[][15], int seats[], char destination[][15], int n){
  37. printf("Enter first name: ");
  38. scanf("%s", first[n]);
  39. printf("Enter last name: ");
  40. scanf("%s", last[n]);
  41. do{
  42. printf("Enter number of seats: ");
  43. scanf("%d", &seats[n]);
  44. if(seats[n] <= 0)
  45. printf("Wrong number\n");
  46. }while(seats[n] <= 0);
  47. printf("Enter destination: ");
  48. scanf("%s", destination[n]);
  49. }
  50. void GetAmount(float amount[], int PNR){
  51. do{
  52. printf("Enter the amount in SAR: ");
  53. scanf("%f", &amount[PNR]);
  54. if(amount[PNR] <= 0)
  55. printf("Wrong amount\n");
  56. else
  57. printf("Thank you\n\n");
  58. }while(amount[PNR] <= 0);
  59. }
  60. main(){
  61. int seats[MAX], confirmed[MAX], n, reserved[MAX], i, PNR, choice;
  62. float amount[MAX];
  63. char first[MAX][15], last[MAX][15], destination[MAX][15];
  64. FILE *inp, *outp;
  65. inp = fopen("E:reservat.txt", "r");
  66. if(inp == NULL){
  67. printf("Cannot open the file ");
  68. exit(1);
  69. }
  70. for(i = 0; i < MAX; i++)
  71. reserved[i] = 0;
  72. n = 0;
  73. for(int status = fscanf(inp, "%s", first[n]);
  74. status != EOF;
  75. status = fscanf(inp, "%s", first[n])){
  76. fscanf(inp, "%s%d%s%f%d", last[n], &seats[n], destination[n], &amount[n], &confirmed[n]);
  77. reserved[n] = 1;
  78. n++;
  79. }
  80. fclose(inp);
  81. do{
  82. choice = menu();
  83. switch(choice){
  84. case 1: if(n < MAX){
  85. AddNew(first, last, seats, destination, n);
  86. reserved[n] = 1;
  87. printf("Thank You, your reservation number is %d (Unconfirmed)\n\n", n);
  88. n++;
  89. }else
  90. printf("The arrays are full\n\n");
  91. break;
  92. case 2: PNR = GetReservationNumber();
  93. if(reserved[PNR] == 1)
  94. DisplayInfo(first, last, seats, destination, amount, confirmed, PNR);
  95. else
  96. printf("Not Found\n\n");
  97. break;
  98. case 3: PNR = GetReservationNumber();
  99. if(reserved[PNR] == 1)
  100. GetAmount(amount, PNR);
  101. else
  102. printf("Not Found\n\n");
  103. break;
  104. case 4: PNR = GetReservationNumber();
  105. if(reserved[PNR] == 1){
  106. confirmed[PNR] = 1;
  107. printf("The reservation is confirmed\n\n");
  108. }else
  109. printf("Not Found\n\n");
  110. break;
  111. case 5: outp = fopen("a:reservation.txt", "w");
  112. for(i = 0; i < n; i++)
  113. fprintf(outp, "%s %s %d %s %.3f %d\n", first[i], last[i], seats[i], destination[i], amount[i], confirmed[i]);
  114. fclose(outp);
  115. printf("Thank You..");
  116. break;
  117. default: printf("Wrong Choice\n\n");
  118. }
  119. }while(choice != 5);
Last edited by WolfPack; Jul 30th, 2006 at 10:19 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

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

 
0
  #2
Jul 30th, 2006
What is your problem?
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 11
Reputation: priya123 is an unknown quantity at this point 
Solved Threads: 0
priya123 priya123 is offline Offline
Newbie Poster

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

 
0
  #3
Jul 30th, 2006
im getting 2 errors in the lines:for(int status = fscanf(inp, "%s", first[n]);and status != EOF;
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 11
Reputation: priya123 is an unknown quantity at this point 
Solved Threads: 0
priya123 priya123 is offline Offline
Newbie Poster

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

 
0
  #4
Jul 30th, 2006
help meeee....
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

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

 
0
  #5
Jul 30th, 2006
That is what I am trying to do. The least you can do is quit whining.
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

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

 
0
  #6
Jul 30th, 2006
Are you compiling this as C or C++?
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 11
Reputation: priya123 is an unknown quantity at this point 
Solved Threads: 0
priya123 priya123 is offline Offline
Newbie Poster

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

 
0
  #7
Jul 30th, 2006
my program is not getting executed!!there is a problem in the lines i mentioned above.can u please rectify!!!
pria
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 11
Reputation: priya123 is an unknown quantity at this point 
Solved Threads: 0
priya123 priya123 is offline Offline
Newbie Poster

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

 
0
  #8
Jul 30th, 2006
am compiling it in turboc.could u trace anything???
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

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

 
0
  #9
Jul 30th, 2006
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.
Last edited by WolfPack; Jul 30th, 2006 at 10:42 am.
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 11
Reputation: priya123 is an unknown quantity at this point 
Solved Threads: 0
priya123 priya123 is offline Offline
Newbie Poster

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

 
0
  #10
Jul 30th, 2006
hey sorry to disturb you!!i have to submit my assignment 2moro!!so im lil tensed...did u trace where ive gone wrong????
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC