Thread: Something's not working..?

  1. #16
    Guest00
    Guest
    Originally posted by Monster
    Do you mean, put the Option1_Reserve and ReserveSeat into 1 function? Yes you can do that. No, I don't think it's a good idea to do that. You can put it all in main if you want but it's better to divide your code in logical steps (parts) and inplement each step in a function.

    About the return... I'm not sure about that. Normally it should return to the calling function.

    What OS/compiler do you use?
    no i meant doing everything in the ReserveSeat function...
    i use Microsoft Visual C++ Professional Edition ... (yes i know MS sucks.. but my school uses MS.. no choice..)

  2. #17
    Guest00
    Guest
    oops forgot to post it..
    ok here it is:

    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "custom.h"
    
    struct SmokingPassenger Spassenger[12];
    struct NonSmokingPassenger NSpassenger[6];
    struct waitinglist waiting_list[9];
    int smoking_space=6;
    int nonsmoking_space=12;
    int nonsmoking_row=1;
    int nonsmoking_seat=1;
    int smoking_row=1;
    int smoking_seat=1;
    int ArrayNo=0;
    int WLArrayNo=0;
    
    // Start of Main
    void main(void)
    {
    	// Declarations
    	int Option;
    	int quit=0;
    
    	// Loop
    	do	{
    
    	// Menu
    	system("cls");
    	printf("GREEN AIRLINE ON-LINE RESERVATION SYSTEM\n");
    	printf("(1)   Reserve a seat\n");
    	printf("(2)   Cancel a reservation\n");
    	printf("(3)   Display seating arrangement\n");
    	printf("(4)   View waiting list\n");
    	printf("(5)   Quit\n");
    	printf("Choose an option: ");
    	fflush(stdin);
    	scanf("%d", &Option);
    
    	if (Option==1)
    	{
    		system("cls");
    		Option1_Reserve();
    	}
    	else if (Option==2)
    	{
    		system("cls");
    		Option2_Cancel();
    	}
    	else if (Option==3)
    	{
    		system("cls");
    		Option3_Display();
    	}
    	else if (Option==4)
    	{
    		system("cls");
    //		Option4_ViewList();
    	}
    	else if (Option==5)
    	{
    		system("cls");
    		quit=Option5_Quit();
    	}
    	else
    	{
    		printf("Please enter a number from 1-5");
    	}
    
    	// End of Menu
    
    	// End of Loop
    	}	while (quit==0);
    
    // End of Main
    }

  3. #18
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Or you can zip your complete project (only sources and workspace) and attach it in your post (I'm also using MS Visual Studio 6.0 Professional Edition).

  4. #19
    Guest00
    Guest
    hmm ok i dunno what i did.. i think it might be fixing the for loops, but now i return to the main(); .. i don't exit the program anymore..

  5. #20
    Registered User
    Join Date
    Oct 2002
    Posts
    8
    Hi, Guest00 here..

    here's my project files...

  6. #21
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Can you also attach the project file (.dsp)?

  7. #22
    Registered User
    Join Date
    Oct 2002
    Posts
    8
    oops.. here:

  8. #23
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Have you used #define before?
    Sorry, stupid question...

  9. #24
    Registered User
    Join Date
    Oct 2002
    Posts
    8
    no, my lecturer helped me with that.. i reckon its way above my level?

  10. #25
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    #define is very easy

    You can use it to replace to following lines:
    Code:
    int smoking_space=6;
    int nonsmoking_space=12;
    By
    Code:
    #define SMOKING_SPACE 6
    #define NONSMOKING_SPACE
    The compiler will replace all SMOKING_SPACE defines with 6 and NONSMOKING_SPACE with 12. But that's something you will learn lateron. You don't have to use defines.

    The code looks great...

    Some small things:

    Option3_Display.cpp:
    - remove void main(void);
    - remove call to main at the end of your function

    Option2_Cancel:
    - remove void main(void);

    Option1_Reserve
    - remove void main(void);

    ProjectSource:
    - change void main(void) to int main(void)
    - return 0 at the end of main

    Cheers,
    Monster

  11. #26
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    And something else. In the main function you use if/else if to find out what the user has entered. You can also use the switch statement:
    Code:
    switch(Option)
    {
    	case 1:	system("cls");
    		Option1_Reserve();
    		break;
    
    	case 2:	system("cls");
    		Option2_Cancel();
    		break;
    
    	case 3:	system("cls");
    		Option3_Display();
    		break;
    
    	case 4:	system("cls");
    		/* Option4_ViewList(); */
    		break;
    
    	case 5:	system("cls");
    		Option5_Quit();
    		break;
    
    	default: printf("Please enter a number from 1-5");
    		break;
    }

  12. #27
    Registered User
    Join Date
    Oct 2002
    Posts
    8
    wow thanks for the corrections..

    yeah i know how to use switch-case.. prefer if else for most situations though =\

    btw here's a function i wrote for updating the waiting list, if for example someone cancels a reservation, then one in the waiting list is moved to the free seat, the rest of the ppl in the list move up the list..

    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "custom.h"
    
    extern struct SmokingPassenger Spassenger[12];
    extern struct NonSmokingPassenger NSpassenger[6];
    extern struct waitinglist waiting_list[9];
    
    void main(void);
    
    // Start of Option1_Reserve
    void UpdateArray(int ArrayNo)
    {
    	int loop;
    
    	for (loop=ArrayNo;loop<9;loop++)
    	{
    		strcpy(waiting_list[loop].name,waiting_list[loop+1].name);
    	}
    
    }

  13. #28
    Registered User
    Join Date
    Oct 2002
    Posts
    8
    here's the latest set.. there's something wrong with viewing the waiting list.. it won't show.. can you run the program and try?

  14. #29
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    I think it's because you forgot the getch function...

  15. #30
    Registered User
    Join Date
    Oct 2002
    Posts
    8
    oh ok fixed it -.-

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Not working Right
    By raven420smoke in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2005, 03:21 AM
  2. Working on simple Engine
    By bladerunner627 in forum Game Programming
    Replies: 16
    Last Post: 05-25-2005, 11:27 AM
  3. Trying to eject D drive using code, but not working... :(
    By snowfrog in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2005, 07:47 PM
  4. x on upper right corner not working
    By caduardo21 in forum Windows Programming
    Replies: 1
    Last Post: 02-20-2005, 08:35 PM
  5. cygwin -> unix , my code not working properly ;(
    By CyC|OpS in forum C Programming
    Replies: 4
    Last Post: 05-18-2002, 04:08 AM