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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!