Question
// Retire.cpp : Defines the entry point for the console application. // program to convery years to retire // sumin Kang // 9/26/17 #include stdafx.h
// Retire.cpp : Defines the entry point for the console application.
// program to convery years to retire
// sumin Kang
// 9/26/17
#include "stdafx.h"
#include
#include
#include
#include
using namespace std;
int main()
{
//declare files
ifstream inFile;
ofstream outFile;
// declare constants and variables
string name;
int age;
int ageInRetire;
// open files
inFile.open("D:\ etire");
outFile.open("D:\ etire");
// get input from user
cout << "What is your name?";
getline(inFile, name);
cout << "How old are you?";
inFile >> age;
// perform calulations
ageInRetire = 27 + age;
// display results
outFile << " Well, " << name << " can retire in " << ageInRetire << " years.";
// close files
inFile.close();
outFile.close();
// freezen screen
string junk;
cout << " Press any keys to continue...";
cin >> junk;
return (0);
This is my homework guidline:
Modify your Retire.cpp program to accept its input from a disk file named "Retire.dat" and display the output to the screen. Then modify it again to send the output to a disk file name "retire.out".
And I did above code, and my inFile is retire.dat which is
Sumin 21
then I have a file will become outFile, but it is strange.
I have a result that
"Well, Sumin can retire in 48 years."
but my file's result is
Well, can retire in -858993433 years.
How do I fix it?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started