I need to add to variable and get the result to be held in another variable, here what ive out but its giving me errors:
printf("The total number of passengers onboard is %d\n\n", &totalpassengers = passengers + cardpassengers);
I need to add to variable and get the result to be held in another variable, here what ive out but its giving me errors:
printf("The total number of passengers onboard is %d\n\n", &totalpassengers = passengers + cardpassengers);
ssharish2005Code:printf("The total number of passengers onboard is %d\n\n", totalpassengers = passengers + cardpassengers);
Last edited by ssharish2005; 01-15-2006 at 09:41 AM.
The code is going round on a loop and everytime I need it to add the prevoius result to the total which it total passengers;
Code:/*************************************************/ /**** Bus Ticketing System ****/ /*************************************************/ #include <stdio.h> #include <conio.h> #include "bcio2.h" #include <time.h> void cash(void);//function prototype void card(void);//function prototype void time(void);//function prototype void welcome(void);//function prototype void totalpassengers(void);//function prototype main() { int passengers =0; int stops; int testnum; int totalpassengers = 0; int cardpassengers = 0; for(stops = 1; stops < 13 ; stops++) { do{ welcome(); time(); totalpassengers = passengers + cardpassengers; printf("The total number of passengers onboard is %d\n\n", totalpassengers = passengers + cardpassengers); printf("This is stop number %d\n\n", stops); printf("Enter number of passengers for this one ticket\n\n"); scanf("%d", &passengers); printf("Any bus passes? enter number\n\n"); scanf("%d", &cardpassengers); printf("The cost of the ticket will be %.2f\n\n", passengers * 0.75); getch(); clrscr(); switch(testnum) { case 0 : continue;//function call break; case 1 : cash();//function call break; case 2 : card();//function call break; } }while(testnum !=0); return 0; } } /***********************************/ /*** Start Of Function Defintions***/ /***********************************/ void cash(void)//function defintions { printf("There are %.2f passengers on this ticket, passengers * 0.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"); }
u need to align the code properly first of all
2. u dont get any value to exit from a loop u chek testnum is not equal but initally u havn't initialzed the testnu value. which actuall contains some junkCode:int main() { int passengers =0; int stops; int testnum=0; int totalpassengers = 0; int cardpassengers = 0; for(stops = 1; stops < 13 ; stops++) { do { welcome(); time(); printf("The total number of passengers onboard is %d\n\n", totalpassengers = passengers + cardpassengers); printf("This is stop number %d\n\n", stops); printf("Enter number of passengers for this one ticket\n\n"); scanf("%d", &passengers); printf("Any bus passes? enter number\n\n"); scanf("%d", &cardpassengers); printf("The cost of the ticket will be %.2f\n\n", passengers * 0.75); printf("Test num : "); scanf("%d",&testnum); getch(); clrscr(); switch(testnum) { case 0 : continue;//function call break; case 1 : cash();//function call break; case 2 : card();//function call break; } }while(testnum !=0); } return 0; }
3. see the highlighted code
ssharish2005
totalpassengers = passengers + cardpassengers;
printf("The total number of passengers onboard is %d\n\n", totalpassengers);
Also, shouldn't you be doing this calculation AFTER you've input some data?
Also, time() is the name of a function in time.h. Declaring your own time() function as well simply confuses things.