5 Replies - 1105 Views - Last Post: 05 October 2005 - 07:56 PM Rate Topic: -----

#1 Kcbroncofan  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 55
  • Joined: 28-September 05

Storing Data to a File

Post icon  Posted 05 October 2005 - 04:29 PM

I have an assignment due. The assignment asks to calculate the property tax. I already got this code done. I need to put this in a file. How do I get data into a file. Then I need to put the file into program and then get the file to open.

This post has been edited by Kcbroncofan: 05 October 2005 - 06:03 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Storing Data to a File

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 247
  • View blog
  • Posts: 13,505
  • Joined: 12-July 02

Re: Storing Data to a File

Posted 05 October 2005 - 06:50 PM

Sounds like you just need to open a file for writing, and open for reading. As you've not posted any code, I'm not sure what your variable names are, but here is a look at file IO in C++.
Was This Post Helpful? 0
  • +
  • -

#3 Kcbroncofan  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 55
  • Joined: 28-September 05

Re: Storing Data to a File

Posted 05 October 2005 - 07:05 PM

This is what I have so far:

#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;
double aval;
double proptaxamt;
double trate = 1.05;
double proptax;

int main()
{
	cout << "Enter the assesed value of the property. $";
	cin >> aval;
	

	ifstream inData;
	ofstream outData;

	inData.open("prog.dat");
	outData.open("prog.out");

	
  
  proptaxamt = aval * 0.92;
  proptax = proptaxamt * trate / 100;
   
	
	cout << fixed << showpoint;
	cout << "Assessed Value: " << setprecision(2) << aval << endl;
	cout << "Taxable Amount: " << proptaxamt << endl;
	cout << "Tax Rate for each $100.00: " << trate << endl;
	cout << "Property Tax: " << proptax << endl;

	inData.close();
	outData.close();

	return 0;

}



I am not sure what I need to do next.
Was This Post Helpful? 0
  • +
  • -

#4 Nova Dragoon  Icon User is offline

  • The Innocent Shall Suffer, Big Time
  • member icon

Reputation: 36
  • View blog
  • Posts: 6,169
  • Joined: 16-August 01

Re: Storing Data to a File

Posted 05 October 2005 - 07:25 PM

What specific things need to go into the file, and when do they need to go there

and likewise what specific things need to be read from the file, where do they need to go and when does that need to happen
Was This Post Helpful? 0
  • +
  • -

#5 Kcbroncofan  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 55
  • Joined: 28-September 05

Re: Storing Data to a File

Posted 05 October 2005 - 07:51 PM

This is what needs to be in the file:
cout << fixed << showpoint;
cout << "Assessed Value: " << setprecision(2) << aval << endl;
cout << "Taxable Amount: " << proptaxamt << endl;
cout << "Tax Rate for each $100.00: " << trate << endl;
cout << "Property Tax: " << proptax << endl;
Was This Post Helpful? 0
  • +
  • -

#6 Nova Dragoon  Icon User is offline

  • The Innocent Shall Suffer, Big Time
  • member icon

Reputation: 36
  • View blog
  • Posts: 6,169
  • Joined: 16-August 01

Re: Storing Data to a File

Posted 05 October 2005 - 07:56 PM

ah

the object cout direct what is put into it by << to the screen

likewise you defined file objects
ifstream inData;
ofstream outData;

the ofstream outData is a file output object, that works the exact same way as cout

just duplicate or replace cout with outData.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1