Question: #include #include // ifstream using namespace std; void execute(char, int, int); // prototype bool GetSuff(ifstream&, char&, int&, int&); int main() { ifstream fin(MooseMoose.txt); // get
#include#include // ifstream using namespace std; void execute(char, int, int); // prototype bool GetSuff(ifstream&, char&, int&, int&); int main() { ifstream fin("MooseMoose.txt"); // get data from file if (!fin.is_open()) { cout << " file not found "; exit(0); } char cmd; int num1, num2; do { bool done = GetSuff(fin, cmd, num1, num2); if (done) break; execute(cmd, num1, num2); } while (true); fin.close(); // explicitly close the file. cout << " program completed "; return 0; } bool GetSuff(ifstream& fin, char& cmd, int& num1, int& num2) { fin >> cmd; // cin >> cmd; if (toupper(cmd) == 'Q') return true; fin >> num1 >> num2; //cin >> num1 >> num2 return false; // keep getting data } void execute(char cmd, int num1, int num2) { int result; // switch statement if (cmd == '+') result = num1 + num2; else if (cmd == '-') result = num1 - num2; else if (cmd = 'x') result = num1 * num2; else if (cmd == '/') result = num1 / num2; else if (cmd == 'g') result = 2 * num1 + num2; // linear g(x,y) else { cout << "bad operation code "; exit(0); } // crash and burn.... better crash early, then produce bad results. cout << result << "=" << num1 << cmd << num2 << endl; }
CAN ANYONE HELP ME TO FIGURE OUT WHY THE CODE IS NOT RUNNING AND TO CHANGE THE "IF STATEMENT TO A SWITCH STAMENT" I WILL APRETIATE IT
thank you
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
