Need help Gas Station Program

SeanBlack0000 0 Tallied Votes 470 Views Share

In this snippet of code, I am trying to check the customers request against the volume remaining in the tank. If the request is greater, I need to instruct the customer to move to the next tank. But I am having problems. The tank is set to store 100 gallons. On the 1st request, I ask for more than 100 gallons, and instead of moving to the next pump it I am told to try another station.

The second problem is if the 1st customer is dispensed an amount less than the 100 gallon capacity, the 2nd customer can also be issued an amount less than the 100 gallons, instead of being moved to the next pump.

Any help will be appreciated.

if (listOfPumps[pumpSelection]->checkRorP(grade, quantity)== true)
{
		listOfPumps[pumpSelection]->dispense(grade, quantity);
		numOfCustomers--;
		listOfPumps[pumpSelection]->getVolume(grade);
	} // end if check == true
					
else // checkRorP == false
	{
	        int nextPump = pumpSelection%5 + 1 ;
		while (nextPump != pumpSelection)
		{
			if (listOfPumps[nextPump]->checkRorP(grade, quantity)==true)
			{
			        listOfPumps[nextPump]->dispense(grade, quantity);
				numOfCustomers--;	
				listOfPumps[nextPump]->getVolume(grade);
				break; 
			}  // end if
			
                        else
			       nextPump = nextPump%5 + 1;
		}
						
                if (nextPump == pumpSelection)
		{
			cout << "Sorry, we cannot service you. Please try another gas station. Sorry for the inconvenience\n" ;
			numOfCustomers--;
		}

}
if (listOfPumps[pumpSelection]->checkRorP(grade, quantity)== true)
{
		listOfPumps[pumpSelection]->dispense(grade, quantity);
		numOfCustomers--;
		listOfPumps[pumpSelection]->getVolume(grade);
	} // end if check == true
					
else // checkRorP == false
	{
	        int nextPump = pumpSelection%5 + 1 ;
		while (nextPump != pumpSelection)
		{
			if (listOfPumps[nextPump]->checkRorP(grade, quantity)==true)
			{
			        listOfPumps[nextPump]->dispense(grade, quantity);
				numOfCustomers--;	
				listOfPumps[nextPump]->getVolume(grade);
				break; 
			}  // end if
			
                        else
			       nextPump = nextPump%5 + 1;
		}
						
                if (nextPump == pumpSelection)
		{
			cout << "Sorry, we cannot service you. Please try another gas station. Sorry for the inconvenience\n" ;
			numOfCustomers--;
		}

}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

This is NOT a code snippet, this is a help request. Post properly. Look up what a code snippet is if you are unsure.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.