
Check severeal boolean returns in same time?
2 Answers By Expert Tutors

Patrick B. answered 06/23/19
Math and computer tutor/teacher
#include <stdio.h>
typedef int boolean;
typedef int bool;
#define TRUE (1)
#define FALSE (0)
typedef boolean (* PFuncPtr) (void);
// You can change these as you like
boolean P1() { printf(" P1 \n"); return(TRUE); }
boolean P2() { printf(" P2 \n"); return(TRUE); }
boolean P3() { printf(" P3 \n"); return(TRUE); }
boolean P4() { printf(" P4 \n"); return(TRUE); }
boolean P5() { printf(" P5 \n"); return(TRUE); }
boolean P6() { printf(" P6 \n"); return(TRUE); }
boolean P7() { printf(" P7 \n"); return(TRUE); }
boolean Go(int i)
{
int iLoop;
PFuncPtr P[7];
boolean bReturn = TRUE;
printf(" i = %d \n",i);
P[0] = P1;
P[1]= P2;
P[2]= P3;
P[3]= P4;
P[4]= P5;
P[5]= P6;
P[6]= P7;
if ((i<1)||(i>7))
{
printf(" invalid input: integer must be 1,2,3,4,5,6,7 \n ");
}
else
{
for (iLoop=0; iLoop<i; iLoop++)
{
if (!P[iLoop])
{
bReturn = FALSE;
break;
}
}
}
return(bReturn);
} //Go
int main()
{
boolean bReturn = Go(3);
printf("%d \n",bReturn);
}

Patrick B. answered 06/22/19
Math and computer tutor/teacher
#include <stdio.h>
typedef int boolean;
typedef int bool;
#define TRUE (1)
#define FALSE (0)
typedef boolean (* PFuncPtr) (void);
// You can change these as you like
boolean P1() { printf(" P1 \n"); return(TRUE); }
boolean P2() { printf(" P2 \n"); return(TRUE); }
boolean P3() { printf(" P3 \n"); return(TRUE); }
boolean P4() { printf(" P4 \n"); return(TRUE); }
boolean P5() { printf(" P5 \n"); return(TRUE); }
boolean P6() { printf(" P6 \n"); return(TRUE); }
boolean P7() { printf(" P7 \n"); return(TRUE); }
boolean Go(int i)
{
int iLoop;
PFuncPtr P[7];
boolean bReturn = TRUE;
printf(" i = %d \n",i);
P[0] = P1;
P[1]= P2;
P[2]= P3;
P[3]= P4;
P[4]= P5;
P[5]= P6;
P[6]= P7;
if ((i<1)||(i>7))
{
printf(" invalid input: integer must be 1,2,3,4,5,6,7 \n ");
}
else
{
for (iLoop=0; iLoop<i; iLoop++)
{
if (!P[iLoop])
{
bReturn = FALSE;
break;
}
}
}
return(bReturn);
} //Go
int main()
{
boolean bReturn = Go(3);
printf("%d \n",bReturn);
}
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
All of the function * P take no arguments and returns boolean. So you can create the array and pointers to these functions and call them with a for loop instead of switch06/22/19