Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a while loop code that will input a text document and output another text

ID: 3623730 • Letter: W

Question

Write a while loop code that will input a text document and output another text document using if - else statment

text input:
remainder 19 9
divide 14 12
multiply 19 9
subtract 13 5
subtract 9 5
divide 5 14
multiply 9 8
divide 11 6
subtract 16 7
subtract 11 12
add 15 6
subtract 16 13
subtract 15 14
divide 17 11
divide 12 12
subtract 17 11
divide 18 6
add 13 13
subtract 9 13
remainder 14 13
multiply 12 7
add 13 10
add 10 6
add 16 5
remainder 17 13

and text output
#1 Operation #2 Answer
19 % 9 1
14 / 12 1
19 * 9 171
13 - 5 8
9 - 5 4
5 / 14 0
9 * 8 72
11 / 6 1
16 - 7 9
11 - 12 -1
15 + 6 21
16 - 13 3
15 - 14 1
17 / 11 1
12 / 12 1
17 - 11 6
18 / 6 3
13 + 13 26
9 - 13 -4
14 % 13 1
12 * 7 84
13 + 10 23
10 + 6 16
16 + 5 21
17 % 13 4

Explanation / Answer

please rate - thanks

#include <iostream>
#include <fstream>
using namespace std;
int main()
{string operation;
ifstream in;
ofstream out;
int num1,num2,result;
char filename[20],op;
cout<<"Enter input file name: ";
cin>>filename;
in.open(filename);       
if(in.fail())           
   { cout<<"input file did not open please check it ";
   system("pause");
   return 1;
   }
cout<<"Enter output file name: ";
cin>>filename;  
out.open(filename);
out<<"#1 Operation #2 Answer ";
in>>operation;
while(in)
    {in>>num1>>num2;
     if(operation.compare("add")==0)
           {op='+';
             result=num1+num2;
             }
     else if(operation.compare("subtract")==0)
            {op='-';
             result=num1-num2;
             }
     else if(operation.compare("multiply")==0)
             {op='*';
             result=num1*num2;
             }
     else if(operation.compare("divide")==0)
             {op='/';
             result=num1/num2;
             }
     else
             {op='%';
             result=num1%num2;
             }
      out<<num1<<"      "<<op<<" "<<num2<<" "<<result<<endl;       
in>>operation;
}
out.close();
in.close();

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote