Question about my project.

I was told to check if my booking time to and from are taken.
So how do i check it?
i was told to use if(condition) , but i do not know what to put inside the condition.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 float timef=900;
	 printf("Booking time from (24hours) :");
	 scanf("%f",&timef);
	 while(timef <900 || timef > 2100)
	 {   printf("***************** [Error Message : Please Re-enter it] *********************** \n");
		 printf("Booking time from (24hours) : ");
	 scanf("%f",&timef);}

	  float timet=900;
	 printf("Booking time to (24hours) : ");
	 scanf("%f",&timet);
     while(timet <900 || timet > 2100 )
	 {   printf("***************** [Error Message : Please Re-enter it] ************************ \n");
		 printf("Booking time to (24hours): ");
	 scanf("%f",&timet);}
	 }
you need an array where you store all the times.
Iterate the array to see whether the time is taken or not.

the best would be to introduce struct like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
struct booking_times
{
  float from;
  float to;
};

...

booking_times my_booking_times[1000];
int number_of_booking_times = 0

...

for(int i = 0; i < number_of_booking_times; i++)
{
  if(bt[i].from == timef)
    ...
}
is there any others ways of doing it?
because i'm still a beginner.i don't really understand it.
And i was to told present my this programme to my teacher.

there's no way around the array. But you can use two arrays (for the two times) with one index and size instead of the struct
Can you give me a example so I can work on it ?
I'm sure your C++ textbook has examples of creating and using arrays.
Sorry,I'm a bit newbie to C++ programming.
Hope you would understand me.
but what do you means with one index and size instead of the struct.


Topic archived. No new replies allowed.