Thread: Simple C Problem

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    5

    Simple C Problem

    Needing to make a application in Visual C++ that can will be used on a bus ticketing programme. I get no errors in my code but when I run it and enter the first number it errors can any one help;

    Code:
    /*************************************************/ 
    /****          Bus Ticketing System                                      ****/ 
    /************************************************/ 
    
    #include <stdio.h> 
    #include <conio.h> 
    #include <time.h>
    
    void cash(void);//function prototype
    void card(void);//function prototype
    void time(void);//function prototype
    void welcome(void);//function prototype
    
    main()
    {
    	int passengers =0;
    	int stops;
        int testnum = 0;
    
    		for(stops = 1; stops < 13 ; stops++) {
    	
    	do{
    		welcome();
    		time();
    		
    		printf("This is stop number %d\n\n", stops);
    		
    		printf("Enter number of passengers for this one ticket\n\n");
    		
    		scanf("%d", passengers);
    
    		printf("The cost of the ticket will be %d", passengers * 75);
    		
    		switch(testnum) {
    		case 0 : continue;//function call
    			break;
    		case 1 : cash();//function call
    			break;
    		case 2 : card();//function call
    			break;
    		default : printf("The number entered was %d\n", testnum);
    			break;
    
    		}
    	}while(testnum !=0);
    	return 0;
    }
    }
    
    	/*** Start Of Function Defintions***/
    
    	void cash(void)//function defintions
    	{
    		printf("There are %d passengers on this ticket, passengers * 75");
    	}
    
    	void card(void)//function definitions
    	{
    		printf("Welcome aboard card holder!");
    	}
    
    	void time(void)//function definitions
    	{
    		        char dateStr [9]; 
              char timeStr [9]; 
              _strdate( dateStr); 
              printf( "The current date is %s \n", dateStr); 
             _strtime( timeStr ); 
             printf( "The current time is %s \n\n", timeStr); 
    	}
    
    	void welcome(void)//function definion
    	{
    		puts("\t\t\tName Edited Out\n\t\t\tBus Ticketing System\n");
    	}

  2. #2
    Registered User
    Join Date
    Nov 2005
    Posts
    85
    what is testnum ? You are always have it set to 0

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    5
    Yes its meant to exit to next stop when pressed, is no longer set to anything and still get the problem.

  4. #4
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Code:
    scanf("%d", &passengers);
    ssharish2005

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A simple file I/O problem
    By eecoder in forum C Programming
    Replies: 10
    Last Post: 10-16-2010, 11:00 PM
  2. Problem in simple code.
    By richdb in forum C Programming
    Replies: 6
    Last Post: 03-20-2006, 02:45 AM
  3. Problem in very simple code
    By richdb in forum C Programming
    Replies: 22
    Last Post: 01-14-2006, 09:10 PM
  4. Simple Initialization Problem
    By PsyK in forum C++ Programming
    Replies: 7
    Last Post: 04-30-2004, 07:37 PM
  5. Simple OO Problem
    By bstempi in forum C++ Programming
    Replies: 1
    Last Post: 04-30-2004, 05:33 PM