Skip to main content
added 25 characters in body
Source Link
pacmaninbw
  • 24.9k
  • 11
  • 46
  • 109
    bool p[LOGICARRAYSIZE] = { true, true, false, false };
    bool q[LOGICARRAYSIZE] = { true, false, true, false };
    bool notp[LOGICARRAYSIZE];
    for (int i = 0; i < LOGICARRAYSIZE; i++ )
    {
        notp[i] = !p[i];
    }
    bool notq[LOGICARRAYSIZE];
    for (int i = 0; i < LOGICARRAYSIZE; i++ )
    {
        notq[i] = !q[i];
    }
    
    GetAllInput(andor, ansp, ansq);


    bool *PParameter;
    bool *QParameter;
    if (ansq == "Y") { // if Not q
       QParameter = q;notq;
    } else {
       QParameter = notq;q;
    }
    if (ansp == "Y") {  // if Not P
       PParameter = p;notp;
    } else {
       PParameter = notp;p;
    }
    if (andor == "AND") {
        OutputAndTable(PParameter, QParameter);
    }
    bool p[LOGICARRAYSIZE] = { true, true, false, false };
    bool q[LOGICARRAYSIZE] = { true, false, true, false };
    bool notp[LOGICARRAYSIZE];
    for (int i = 0; i < LOGICARRAYSIZE; i++ )
    {
        notp[i] = !p[i];
    }
    bool notq[LOGICARRAYSIZE];
    for (int i = 0; i < LOGICARRAYSIZE; i++ )
    {
        notq[i] = !q[i];
    }
    
    GetAllInput(andor, ansp, ansq);


    bool *PParameter;
    bool *QParameter;
    if (ansq == "Y") {
       QParameter = q;
    } else {
       QParameter = notq;
    }
    if (ansp == "Y") {
       PParameter = p;
    } else {
       PParameter = notp;
    }
    if (andor == "AND") {
        OutputAndTable(PParameter, QParameter);
    }
    bool p[LOGICARRAYSIZE] = { true, true, false, false };
    bool q[LOGICARRAYSIZE] = { true, false, true, false };
    bool notp[LOGICARRAYSIZE];
    for (int i = 0; i < LOGICARRAYSIZE; i++ )
    {
        notp[i] = !p[i];
    }
    bool notq[LOGICARRAYSIZE];
    for (int i = 0; i < LOGICARRAYSIZE; i++ )
    {
        notq[i] = !q[i];
    }
    
    GetAllInput(andor, ansp, ansq);


    bool *PParameter;
    bool *QParameter;
    if (ansq == "Y") { // if Not q
       QParameter = notq;
    } else {
       QParameter = q;
    }
    if (ansp == "Y") {  // if Not P
       PParameter = notp;
    } else {
       PParameter = p;
    }
    if (andor == "AND") {
        OutputAndTable(PParameter, QParameter);
    }
Fixed grammar, explained in greater depth why functions are necessary.
Source Link
pacmaninbw
  • 24.9k
  • 11
  • 46
  • 109

To make it more concise you need to use functions. The reason I suggest that you use functions is because your repeat a lot of your code, and you don't have to. If you create functions that contain the code you repeat it will make your code smaller and easier to read, it's like writing chapters in a book or paragraphs in an essay. You repeat your for loops many times, if you use functions such as OutputAndTable() below and an OutputOrTable() function you only have 2 versions of the for loop (if you add the 2 arrays I added which are notp[] and notq[]). Some examples of functions you need are:

To make it more concise you need to use functions. Some examples of functions you need are:

To make it more concise you need to use functions. The reason I suggest that you use functions is because your repeat a lot of your code, and you don't have to. If you create functions that contain the code you repeat it will make your code smaller and easier to read, it's like writing chapters in a book or paragraphs in an essay. You repeat your for loops many times, if you use functions such as OutputAndTable() below and an OutputOrTable() function you only have 2 versions of the for loop (if you add the 2 arrays I added which are notp[] and notq[]). Some examples of functions you need are:

Fixed grammar
Source Link
pacmaninbw
  • 24.9k
  • 11
  • 46
  • 109

The function GetAllInput() show's how you can handle inputs better, although to truely handle inputs better wouldyou would want to loop until you get the correct answer.

The function GetAllInput() show's how you can handle inputs better, although to truely handle inputs better would would want to loop until you get the correct answer.

The function GetAllInput() show's how you can handle inputs better, although to truely handle inputs better you would want to loop until you get the correct answer.

Source Link
pacmaninbw
  • 24.9k
  • 11
  • 46
  • 109
Loading