Create a text file with a letter on the first line, and two double-digit numbers on the second line. Write a program using fstream that reads in your text file, creates variables to manipulate that input and outputs the following results to a different text file:
"The ASCII value of your character: " __ " is " ____"
(you will need to cast from a char to an int)
"The sum of " ___ " and " _____ " = " _____ "
(add the two numbers, display both the numbers and final result)
"The product of " ___ " and " _____ " = " _____"
(multiply the two numbers, display both the numbers and final result)
//Reading from a text file
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <fstream>
using namespace std;
int main ()
{
//Declare variables
ifstream inFile; //Input filestream variable
ofstream outFile; //Output filestream variable
char letter; //Variable to read the letter
int number1, number2; //Variable to read the two numbers
//Open the file and input the data into the new file
inFile.open("C:/Numbers.txt");
outFile.open("C:/FinalData.out");
inFile >> letter;
getline(cin, letter);
outFile << "The ASCII value of your character: " << static_cast<int> (letter) << letter <<endl;
getline(cin, number1);
getline(cin, number2);
inFile >> number1 >> number2;
outFile << "The sum of " << number1 << " and " << number2 << " = " << number1 + number2;
outFile << "The product of " << number1 << " and " <<number2 << " = " << number1 * number2;
inFile.close();
outFile.close();
return 0;
}