bool canMeet=false;
if (((P1T1==P2T1) && (P2T1==P3T1) && (P3T1==P4T1) && (P4T1==P1T1)) == 1)
{
canMeet=true;
cout<< "All the four people can meet at the time 8:00-12:00 \n";
}
if (((P1T2==P2T2) && (P2T2==P3T2) && (P3T2==P4T2) && (P4T2==P1T2)) == 1)
{
canMeet=true;
cout<< "All the four people can meet at the time 12:00-18:00 \n";
}
if (((P1T3==P2T3) && (P2T3==P3T3) && (P3T3==P4T3) && (P4T3==P1T3)) == 1)
{
canMeet=true;
cout<< "All the four people can meet at the time 18:00-23:00 \n";
}
if (!canMeet) cout<< "The 4 people are not free for a meeting at the same time of the day. ";
bool canMeet=false;
if (((P1T1==P2T1) && (P2T1==P3T1) && (P3T1==P4T1) && (P4T1==P1T1)) && (P1T1==1))
{
canMeet=true;
cout<< "All the four people can meet at the time 8:00-12:00 \n";
}
if (((P1T2==P2T2) && (P2T2==P3T2) && (P3T2==P4T2) && (P4T2==P1T2)) && (P1T2==1))
{
canMeet=true;
cout<< "All the four people can meet at the time 12:00-18:00 \n";
}
if (((P1T3==P2T3) && (P2T3==P3T3) && (P3T3==P4T3) && (P4T3==P1T3)) && (P1T3==1))
{
canMeet=true;
cout<< "All the four people can meet at the time 18:00-23:00 \n";
}
if (!canMeet) cout<< "The 4 people are not free for a meeting at the same time of the day. ";
Thank you so much. It does work. But one more thing in the program i created iv written it in such a way so that if the person is free thry can input 1 if not free 0. Still i have to develop it so that the user is not allowed to input any other number, right? So how do i do it.
# include <iostream>
# include <stdio>
# include <stdlib>
int getNum(); // ADD THIS HERE
int main()
{
int P1T1;
int P1T2;
int P1T3;
int P2T1;
int P2T2;
int P2T3;
int P3T1;
int P3T2;
int P3T3;
int P4T1;
int P4T2;
int P4T3;
cout<< "Press 1: If the person is FREE\n\n (OR)\n\nPress 2: If the person is NOT FREE\n\n";
cout<< "Is the 1st person free from 8:00-12:00 : ";
P1T1 = getNum();
cout<< "Is the 1st person free from 12:00-18:00 : ";
P1T2 = getNum(); // CHANGE THESE ALL THE WAY DOWN
cout<< "Is the 1st person free from 18:00-23:00 : ";
P1T3 = getNum();
cout<< "Is the 2nd person free from 8:00-12:00 : ";
cin>> P2T1;
cout<< "Is the 2nd person free from 12:00-18:00 : ";
cin>> P2T2;
cout<< "Is the 2nd person free from 18:00-23:00 : ";
cin>> P2T3;
cout<< "Is the 3rd person free from 8:00-12:00 : ";
cin>> P3T1;
cout<< "Is the 3rd person free from 12:00-18:00 : ";
cin>> P3T2;
cout<< "Is the 3rd person free from 18:00-23:00 : ";
cin>> P3T3;
cout<< "Is the 4th person free from 8:00-12:00 : ";
cin>> P4T1;
cout<< "Is the 4th person free from 12:00-18:00 : ";
cin>> P4T2;
cout<< "Is the 4th person free from 18:00-23:00 : ";
cin>> P4T3;
if (((P1T1==P2T1) && (P2T1==P3T1) && (P3T1==P4T1) && (P4T1==P1T1)) == 1)
cout<< "All the four people can meet at the time 8:00-12:00 \n";
if (((P1T2==P2T2) && (P2T2==P3T2) && (P3T2==P4T2) && (P4T2==P1T2)) == 1)
cout<< "All the four people can meet at the time 12:00-18:00 \n";
if (((P1T3==P2T3) && (P2T3==P3T3) && (P3T3==P4T3) && (P4T3==P1T3)) == 1)
cout<< "All the four people can meet at the time 18:00-23:00 \n";
else
cout<< "The 4 people are not free for a meeting at the same time of the day. ";
getchar ();
}
int getNum() { // ADD THIS FUNCTION HERE
int num;
do {
cin >> num;
if (num!=1 && num!=2) cout << "Enter 1 or 2 only\n";
} while (num!=1 && num!=2);
return num;
}
I only changed a few of your cin >> P... expressions, so you need to finish that up yourself. I hope this helps.
If you do decide to switch to using the value 1 representing they can meet, and 0 that they can't, then your logic statements can become much simpler:
1 2
if ( P1T1 * P2T1 * P3T1 * P4T1 )
cout << "All the four people can meet at the time 8:00-12:00\n";
Because if any of them cannot meet, the product of the multiplication will be zero, which evaluates to false, but if they all can, then 1*1*1*1 is 1, which evaluates to true.
If you are interested in using loops, don't use entirely separate variables. Use arrays.