This code below suppose to repeatedly prompt the user for an hour number and
if the hour is “free mark it as “not taken otherwise tell the user “already
taken, i am doing white box testing.
But it doesn't allow hours to be marked "taken" and also doesn't prompt the
user immediately for another hour. can you check it out for please.

#include "stdafx.h"

#using <mscorlib.dll>
using namespace std;


class Day{
   private:
       int day,month,year;//Date
       bool schedule[9];//Hours 9am-6pm
   public:
       Day(int,int,int);//Constructor
       ~Day();//Destructor
       void setTime(int);
       bool checkTime(int);
       void display();
};

Day::Day(int d,int m,int y){//Pass date to constructor
   day=d;month=m;year=y;//Set the date
   for(int i=0;i<9;++i)schedule[i]=false;//Initialise all the hours in the day to “free
}

Day::~Day(){}

bool Day::checkTime(int t)
{
   if(t>5&&t<9)return 0;//Invalid time
   else t+=(t>=9?-9:3);

   if(!schedule[t])
   {//Check if booked
       schedule[t]=true;//Now booked
       return 1;//Success!
   }
   else return 0;//Not available...
}

void Day::display()
{
   std::cout<<day<<'/'<<month<<'/'<<year<<std::endl;//Display day
   for(int i=0;i<9;++i)
	   std::cout<<(i<4?i+9:i-3)<<(i<3?"am":"pm")<<'\t'<<(schedule[i]?"Booked":"Available")
	   <<std::endl;
}
int _tmain()
{
   int d,m,y,t;
   std::cout<<"Input the date:\n";
   std::cin>>d>>m>>y;
   Day MyDay(d,m,y);//Create a day

   do
		{
       std::cout<<"Input appointment time:\n";
       std::cin>>t;
	    }
   while(!MyDay.checkTime(t));//Do until you find a free time

   MyDay.display();

return 0;
	}

:sad:

hi please try with this code, if it can serve your perpose. hope u will not have any problem now....

#include<iostream>
using namespace std ;

class Day{
   private:
       int day,month,year;//Date
       bool schedule[9];//Hours 9am-6pm
   public:
       Day(int,int,int);//Constructor
       ~Day();//Destructor
       void setTime(int);
       bool checkTime(int);
       void display();
	   bool IfAnyTimeAvailable() 
	   {
		   for(int i=0;i<9;++i) {
			   if(!schedule[i]) {
				   return true ;//time is available for booking
			   }
		   }
		   return false ;//no time is available for booking
	   }
};

Day::Day(int d,int m,int y){//Pass date to constructor
   day=d;month=m;year=y;//Set the date
   for(int i=0;i<9;++i)schedule[i]=false;//Initialise all the hours in the day to “free
}

Day::~Day(){}

bool Day::checkTime(int t)
{
   if(t>5&&t<9)return 0;//Invalid time
   else t+=(t>=9?-9:3);

   if(!schedule[t])
   {//Check if booked
       schedule[t]=true;//Now booked
       return 1;//Success!
   }
   else return 0;//Not available...
}

void Day::display()
{
   std::cout<<day<<'/'<<month<<'/'<<year<<std::endl;//Display day
   for(int i=0;i<9;++i)
	   std::cout<<(i<4?i+9:i-3)<<(i<3?"am":"pm")<<'\t'<<(schedule[i]?"Booked":"Available")
	   <<std::endl;
}
int main(void)
{
   int d,m,y,t;
   std::cout<<"Input the date:\n";
   std::cin>>d>>m>>y;
   Day MyDay(d,m,y);//Create a day
   do{
	   std::cout<<"Input appointment time:\n";
       std::cin>>t;
	   if(!MyDay.checkTime(t)) {
		   MyDay.display();
	   }
	   if(!MyDay.IfAnyTimeAvailable()){
		   break ;
	   }
	 }
	while(1);
	cout<<"********All Booked************"<<endl ;
	MyDay.display();

return 0;
}
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.