#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int minimal(int seed);
int main (void)//random=countpassenger;
{
    int check=0, tempEarnings, ctr4, info[17][31],ctr3,capacity=0, ctr, ctr2,denomination[6]={1,5,10,20,50,100}, x[6],seed, random=0, loose=0,y[17]={0}, a, change, money, passenger=0, destination, station, pay, payment, n ,km, earnings, out[17]={0};
    int passengerlimit[17]={0,30,15,10,10,15,20,10,10,20,5,20,15,10,10,5,0};
    printf("Hello, Good day!\nWelcome to our bus! Just seat back and relax.\n\n");
    printf("Please enter the seed: ");
    scanf("%d", &seed);
    for(ctr=0;ctr<=5;ctr++)
    {
                           printf("No. of %d: ", denomination[ctr]);
                           scanf("%d", &x[ctr]);
                           loose=loose+denomination[ctr];
}
    if(seed<=0)
    { return 0;
    }
    
    
    
   
    
   
    
    
    
    for(station=1;station<=16;station++)
    {
    random=1+minimal(seed)%30;
    passenger+=random;
    
    printf("%d passengers entered the bus.\n", random);
    printf("  Passengers that exited: %d\n",out[station]);
    
    
    
    capacity=capacity-out[station];
    if((station==1)||(station==5)||(station==6)||(station==9)||(station==11)||(station==12)||(station==13))         
			{
				y[station]=(minimal(seed)%passengerlimit[station])+1;
				seed=minimal(seed);/*?*/
			}		else
			{
			y[station]=(minimal(seed)%(passengerlimit[station]+1));
			}
			
			if((capacity+y[station])>=60)
		{
			y[station]=60-capacity;/*for the no of passengers to not exceed 60*/
		}
    
    printf("\nCurrent Passenger Count: %d\n", passenger);
    capacity=capacity+y[station];
    passenger+=y[station];
    printf("\tPassenger   Destination   Please pay  Payment / Change\n");
       
    for(ctr3=1;ctr3<=random;ctr3++)//ctr3 is the variable for passenger being accomodated. Example: ctr3rd passenger. let ctr3=7, therefore, 7th passenger.
    {
                                          info[station][ctr3]=(minimal(seed)%(16-station))+station+1;
                                          seed=minimal(seed);
                                          out[info[station][ctr3]]++;
                                          km=abs(destination-station);// pwede alisin ung abs
                                          
    if(km<=4){payment=10;}else if(km==5){payment=12;}else if(km==6){payment=14;}
    else if(km==7){payment=16;}else if(km==8){payment=18;}else if(km==9){payment=20;}
    else if(km==10){payment=22;}else if(km==11){payment=24;}else if(km==12){payment=26;}
    else if(km==13){payment=28;}else if(km==14){payment=30;}else if(km==15){payment=32;}
    
    a=1+minimal(seed)%98;
    if (a<=40)
    {//printf("%d\n", a);
     n=payment;
    //printf("Exact Amount.");
    }
    if(a>40&&a<=70)
    {//printf("%d\n", a); code is not necessary since it just display the chance of the customer's payment.
                    if(payment>20)
                    {n=50;}
                    else{n=20;}
}
    else if(a>70&&a<=90)
    {//printf("%d\n", a); code is not necessary since it just display the chance of the customer's payment.
     n= 50;}
    else if(a>90&&a<=100){n=100;}
    
    
    for(ctr=7;ctr>=1;ctr--)
	{
			while(n>=denomination[ctr])
			{
			 	x[station]++;
				n=n-denomination[ctr];
			}
	}
	
	tempEarnings=tempEarnings+payment;
	change=n-payment;
	
	
	for(ctr=6;ctr>=1;ctr--)
	{
		if(change>=denomination[ctr])
		{
			if((x[ctr]==0)&&(ctr!=1))
				{continue;}
			else
			{
				change-=denomination[ctr];
				--x[ctr];
				++ctr;
			}
		}
		if (x[ctr]<0)
		{
			check=1;
			break;
		}
		else 
		{	check=0;}
	

	
	printf("\t\t%d   /     %d      /   %d    /   %d   /    %d\n",ctr,info[station][ctr],payment,n ,change);
			if(check==1)
			{
				break;
			}
		
		if(check==1)
		{
			break;
		}
		
		printf("  current number of passengers in bus: %d\n",capacity);
		
		
		
		printf("  current number of loose change: \n");
		for(ctr=1;ctr<=6;ctr++)/*j-> counter no.*/
			printf("\tP%d: %d\n",denomination[ctr],x[ctr]);
		
	}}}
	if(check==1)
	{
		printf("\n\nInsufficient loose change...\n");
		printf("Loose Change remaining:\n");
		for(ctr=1;ctr<=6;ctr++)
			printf("  P%d : %d\n",denomination[ctr],x[ctr]);
	}
	else
	{
	printf("Trip Summary:\n");
	printf("Total number of passengers that entered: %d\n",passenger);
	
	}

	scanf("%d",&a);
	return 0;
    
  
} 
    
    
 int minimal(int seed)
 {int s1;
  double temp;
 
  temp=seed*48271.0;
  temp=fmod(temp, 2147483647);
  s1=(int) temp;
 
  return (s1);
 }

Edited 7 Years Ago by WaltP: Added CODE tags -- with all the help about them, how could you miss using them????

If you can't give us any more information than just posting almost 200 lines of uncommented code with no indication what's wrong, where it's wrong, and not using CODE tags, then there's no real help we can give.

Can you please tell us what the program is supposed to do? The code compiles fine but we won't be able to help you fix it if you don't tell us what the code is supposed to be doing. Thanks.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,d,e,f,g,h,i,j,k,l,change;
printf("Enter the money:");
scanf("%d",&a);
printf("\nEnter the price:");
scanf("%d",&b);
change=a-b;
printf("\nChange= %d",change);
if(change>=1000)
{
d=change/1000;
printf("\nThousand= %d",d);
}
if(change>=500)
{
e=(change%1000/500);
printf("\n5 hundred= %d",e);
}
if(change>=200)
{
f=(change%500/200);
printf("\n2 hundred= %d",f);
}
if(change>=100)
{
g=(change%200/100);
printf("\nhundred= %d",g);
}
if(change>=50)
{
h=(change%100/50);
printf("\nfifty= %d",h);
}
if(change>=20)
{
i=(change%50/20);
printf("\nTwenty= %d",i);
}
if(change>=10)
{
j=(change%20/10);
printf("\nTen= %d",j);
}
if(change>=5)
{
k=(change%10/5);
printf("\nFive= %d",k);
}
if(change>=1)
{
l=(change%5/1);
printf("\nPeso= %d",l);
}
getch();
}

Edited 5 Years Ago by ~s.o.s~: added code tags; learn to use them.

This article has been dead for over six months. Start a new discussion instead.