I am a new programming student and my assignment is to 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)
Here is what I have coded:
#include <fstream>
using namespace std;
int main()
{
ifstream inStream;
ofstream outStream;
char aChar='L';
int charVal = aChar; //to get ASCII value of variable
//Open the files
inStream.open("input.txt");
outStream.open("output.txt");
char first;
int firstnum, secondnum;
inStream >> first;
outStream << "The ASCII value of your character: " << (first) << " is " << (+charVal) << endl;
inStream >> firstnum >> secondnum;
outStream << "The sum of " << (firstnum) << (secondnum) << " is " << (firstnum + secondnum) << endl;
inStream >> firstnum >> secondnum;
outStream << "The product of " << (firstnum) << (secondnum) << " is " << (firstnum * secondnum) << endl;
return 0;
}
My input text doc is
L
24 25
and my output doc is coming up as
The ASCII value of your character: is 76
The sum of 083 is 83
The product of 083 is 0
Can someone explain to me what I am doing wrong and why this isn't working properly. I would really appreciate the help.
"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)
Here is what I have coded:
#include <fstream>
using namespace std;
int main()
{
ifstream inStream;
ofstream outStream;
char aChar='L';
int charVal = aChar; //to get ASCII value of variable
//Open the files
inStream.open("input.txt");
outStream.open("output.txt");
char first;
int firstnum, secondnum;
inStream >> first;
outStream << "The ASCII value of your character: " << (first) << " is " << (+charVal) << endl;
inStream >> firstnum >> secondnum;
outStream << "The sum of " << (firstnum) << (secondnum) << " is " << (firstnum + secondnum) << endl;
inStream >> firstnum >> secondnum;
outStream << "The product of " << (firstnum) << (secondnum) << " is " << (firstnum * secondnum) << endl;
return 0;
}
My input text doc is
L
24 25
and my output doc is coming up as
The ASCII value of your character: is 76
The sum of 083 is 83
The product of 083 is 0
Can someone explain to me what I am doing wrong and why this isn't working properly. I would really appreciate the help.