Hello All!
I am having trouble with my C++ code. The problem is that my code isn't giving me the correct logic outputs, Also, my teacher said to MUST MAKE the output look like this :
P and Q : T P or Q : T P --> Q : T
P and Q : F P or Q : T P --> Q : F
P and Q : F P or Q : F P --> Q : T
I am reading from a text file too. It's called prog2_input.txt and this is what it contains:
P Q
T F
F T
F F
T T
T F
F T
F F
this is the code I have so far, and any help is very appreciated :) Thanks! Oh, and NO advanced stuff please,
teacher said its very simple, and it should be a lot like the code that I have.
#include <iostream> // Include statement(s) //
#include <fstream>
using namespace std; // Using namespace statement(s) //
int main() {
char storage; // Variable declaration(s) //
char letter1;
char letter2;
ifstream input;
input.open("prog2_input.txt"); // Opening file of txt from ifstream - input //
input >> letter1 >> letter2; // input is reading each character as letter1 then letter2 //
while (input >> storage) { // Placeholder for characters being read //
cout << "P: " << storage << '\t'; // Outputs the storage for P being held //
input >> storage; // Continues to read input //
cout << "Q: " << storage << endl; // Outputs the storage for Q being held //
if (letter1 && letter2) {
// P and Q //
cout << "P and Q: " << storage << ' ';
//input >> storage;
}
if (letter1 || letter2) {
// P or Q //
cout << "P or Q: " << storage << ' ';
}
if ((!letter1) || (letter1 && letter2)) {
// If P then Q //
cout << "P --> Q: " << storage << endl;
}
}
input.close(); // Close input file //
system ("PAUSE"); // Black box to appear //
return 0; // return statement(s) //
}