I am working on a programming assignment using C++ and am lost as to how to make a group of answers print to my file called "mathops.out". I have a list with + 2 14, + 528 826, * 2 64, / 6 2 and am trying to have my program compute these problems and have them output to my file. Any ideas?
The program runs as is but it will only output one answer when I use ./a.out and then enter in + 2 14 I want more.
Thanks
#include <iostream>
#include <fstream>
using namespace std;
void ShowMathTable(ofstream & fOut);
int Add(int a, int b);
int Subtract(int a, int b);
int Multiply(int a, int b);
int Divide(int a, int b);
int Mod(int a, int b);
int main()
{
ofstream fOut;
fOut.open("mathops.out",ios:

ut);
if(!fOut)
{
cout << "Unable to open..." << endl;
}
ShowMathTable(fOut);
fOut.close();
return 0;
}
void ShowMathTable(ofstream & fOut)
{
char op; // operator
int a, b; // variables
int result;
cout << "Enter an expression "<< flush;
cout << "in the form: op number number"<< endl;
cin >> op >> a >> b; // inputs values here
if(op == '+')
{
result = Add(a, b);
cout << a << "+" << b << "=" << result << endl;
fOut << a << "+" << b << "=" << result << endl;
}
if(op == '-')
{
result = Subtract(a, b);
cout << a << "-" << b << "=" << result << endl;
fOut << a << "-" << b << "=" << result << endl;
}
if(op == '*')
{
result = Multiply(a, b);
cout << a << "*" << b << "=" << result << endl;
fOut << a << "*" << b << "=" << result << endl;
}
if(op == '/')
{
result = Divide(a, b);
cout << a << "/" << b << "=" << result << endl;
fOut << a << "/" << b << "=" << result << endl;
}
if(op == '%')
{
result = Mod(a, b);
cout << a << "%" << b << "=" << result << endl;
fOut << a << "%" << b << "=" << result << endl;
}
}
int Add(int a, int b) // Add - add two integers, return result
{
int result;
result = a + b;
return result;
}
int Subtract(int a, int b) // Subtract - subtract two integers, return result
{
int result;
result = a - b;
return result;
}
int Multiply(int a, int b) // Multiply - multiply two integers, return result
{
int result;
result = a * b;
return result;
}
int Divide(int a, int b) // Divide - divide two integers, return result
{
int result;
result = a / b;
return result;
}
int Mod(int a, int b) // Mod Operator - mod two integers, return result
{
int result;
result = a % b;
return result;
}