Jump to content

Need some help with a function

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
restin84

restin84

    Learning Programmer

  • Members
  • PipPipPip
  • 53 posts
Hey guys. So I am writing a program for comp sci I, and it is a program that a hotel clerk can use to list rooms, check in, check out etc. I have one function to list vacant rooms by preference(single, double, or suite). I can list the rooms by preference but I'm having a hard time working out the control structure to state that there are no vacant rooms available to fit the request. Here is the function. Its gotta be an easy change but I don't know what to do. Any suggestions?
void Hotel::ListVacantType()
{
	int type;
	int i = 0;
	cout << "Please select room type\n"
		 << "1 - Single\n"
		 << "2 - Double\n"
		 << "3 - Suite\n";
	cin >> type;
	
	//int counter = 0;	
	while(i < numberOfRooms)
	{
		
		
		if(type == 1) //&& roomPtr[i].GetSmokePreference() == true)
		{
			if(roomPtr[i].GetType() == Single && roomPtr[i].GetStatus() == vacant)
			{
				GetRoomInfo(roomPtr[i]);
				//counter++;
			}
			/*else
			{
				counter = 0;
			}*/
			
		}
		else if(type == 2)// && roomPtr[i].GetSmokePreference() == false)
		{
			if(roomPtr[i].GetType() == Double && roomPtr[i].GetStatus() == vacant)
			{
				GetRoomInfo(roomPtr[i]);
				//counter++;
			}
			/*else
			{
				counter = 0;
			}*/
						
		}
		else
		{
			if(roomPtr[i].GetType() == Suite && roomPtr[i].GetStatus() == vacant)
			{
				GetRoomInfo(roomPtr[i]);
				//counter++;
			}
			/*else
			{
				counter = 0;
			}*/
			
		};
		
		i++;
	}
		
		/*if(counter == 0)
		{
			cout << "There are no available rooms to match your request\n";
		}*/
	
	RequestAction();
		
}

the variable i was for a for loop that I took out.

Edited by John, 11 April 2009 - 04:16 PM.


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Why do you have the counter++ lines commented out? I think that's exactly what you need. The "else counter=0" lines definitely need to be removed.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog