6 Replies - 436 Views - Last Post: 02 October 2012 - 02:00 PM Rate Topic: -----

#1 TommehTGOD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 25-March 12

Savings Account Report Help

Posted 02 October 2012 - 08:34 AM

Here are the instructions:
http://faculty.winth...f12-savings.pdf


I am having a little trouble just reading in the the numbers because you see you have the Account Number, Interest Rate, Balance, and 3 sets of Deposits and Withdraws to read in. Before i do any calcuations, I want to make sure that I can read all those numbers in first.

When i check the output, nothing shows...just the headings

This is what i have so far

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
	int Acct;
	double d,w,intrate, bal;
	ofstream Output;
	Output.open("Output.dat");

	ifstream infile;
	infile.open("Input.dat");

	Output<<setw(40)<<"Savings Account Report"<<endl<<endl<<endl;
	Output<<setw(35)<<"Thomas Powe"<<endl;
	Output<<setw(34)<<"10-4-2012"<<endl<<endl;
	Output<<setw(22)<<"Previous"<<setw(53)<<"New"<<endl;
	Output<<setw(10)<<"Account"<<setw(12)<<"Balance"<<setw(13)<<"Deposits"<<setw(15)<<"Withdrawals"<<setw(14)<<"Interest"<<setw(15)<<"Balance"<<endl;

	infile>>Acct>>intrate>>bal;
	while(!infile.eof())
	{

		infile>>d>>w;
		while(w >= 0)
		{	
			//td=d+d;
			//tw=w+w;
			infile>>d>>w;
		}
		Output<<setw(10)<<Acct<<setw(12)<<"bal"<<setw(13)<<d<<setw(15)<<w<<setw(14)<<"intrate"<<setw(15)<<"nbal"<<endl;
		infile>>Acct>>intrate>>bal;
	}

	Output.close();
	infile.close();

	return 0;
}


Please help and thank you!

This post has been edited by TommehTGOD: 02 October 2012 - 08:35 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Savings Account Report Help

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4293
  • View blog
  • Posts: 13,462
  • Joined: 25-December 09

Re: Savings Account Report Help

Posted 02 October 2012 - 08:45 AM

Please show a sample of your input file. However this looks like the probable cause of your problems (look at the comments in the code).
	while(!infile.eof())
	{

		infile>>d>>w; // Read d and w from the file.
		while(w >= 0)
		{	
			//td=d+d;
			//tw=w+w;
			infile>>d>>w; //Read d and w again from the file???? 
		}
		Output<<setw(10)<<Acct<<setw(12)<<"bal"<<setw(13)<<d<<setw(15)<<w<<setw(14)<<"intrate"<<setw(15)<<"nbal"<<endl;


If you have more than two items per line on your file you will probably have problems.

Jim
Was This Post Helpful? 0
  • +
  • -

#3 TommehTGOD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 25-March 12

Re: Savings Account Report Help

Posted 02 October 2012 - 10:59 AM

Here is my input code
4523 0.6 4686.89 0 78 100 0 200 50 -9
4567 1.5 12905.67 0 50 0 0 75 0 -9
4658 0.6 1800.95 0 0 0 0 0 0 -9
4677 0.6 1670.45 2500 600 1200 0 500 50 -9  
4805 1.75 27531.82 200 0 1500 2000 1100 0 -9    
4827 1.5 15963.45 750 0 1200 200 750 100 -9  
4868 0.6 1686.89 300 0 850 100 0 200 -9


I put the -9 there as sentinel values.
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3667
  • View blog
  • Posts: 11,500
  • Joined: 05-May 12

Re: Savings Account Report Help

Posted 02 October 2012 - 11:23 AM

I think your code that looks for the sentinel value has a bug. The sentinel value will not end up in w. Try simulating it on paper if you don't know how to use a debugger.
Was This Post Helpful? 0
  • +
  • -

#5 jimblumberg  Icon User is online

  • member icon


Reputation: 4293
  • View blog
  • Posts: 13,462
  • Joined: 25-December 09

Re: Savings Account Report Help

Posted 02 October 2012 - 11:41 AM

What does each number represent? This looks like you should be using some kind of array/vector or structure/class to hold this information. For example the first column looks like it may be an account number.

You also may want to study the following link: Basic File input and output.

Quote

Hand in: A copy of the pseudocode code, a copy of the source code, and a copy of the
output file.

Also normally you would write your Pseudo code before you write your program. Have you completed that part of the assignment?

Jim
Was This Post Helpful? 0
  • +
  • -

#6 TommehTGOD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 25-March 12

Re: Savings Account Report Help

Posted 02 October 2012 - 01:01 PM

I was able to fix the code reading in the files...Here's what i have so far.

//Thomas Powe
//Program 3
//10-4-2012

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <stdlib.h>
using namespace std;

int main()
{
	int Acct;
	double d,w,intrate, bal;
	double tw, td, nbal, interest, minrate;
	ofstream Output;
	Output.open("Output.dat");

	ifstream infile;
	infile.open("Input.dat");

	Output<<setw(40)<<"Savings Account Report"<<endl<<endl<<endl;
	Output<<setw(35)<<"Thomas Powe"<<endl;
	Output<<setw(34)<<"10-4-2012"<<endl<<endl;
	Output<<setw(22)<<"Previous"<<setw(53)<<"New"<<endl;
	Output<<setw(10)<<"Account"<<setw(12)<<"Balance"<<setw(13)<<"Deposits"<<setw(15)<<"Withdrawals"<<setw(14)<<"Interest"<<setw(15)<<"Balance"<<endl;

	
	infile>>Acct>>intrate>>bal;
	while(!infile.eof())
	{
		d=0;
		w=0;
		td=0;
		tw=0;
		for(int i=1; i<=3; i++)
		{
			infile>>d>>w;
			td=td+d;
			tw=tw+w;
			minrate=(intrate/12);
			nbal=bal+td-tw;
			interest=(minrate/100)*nbal;

		}
		Output<<setw(10)<<Acct<<setw(12)<<setprecision(2)<<fixed<<bal<<setw(13)<<td<<setw(15)<<tw<<setw(14)<<interest<<setw(15)<<nbal<<endl;
		infile>>Acct>>intrate>>bal;
	}

	Output.close();
	infile.close();

	return 0;
}


Now what's giving me problem right now is #3 on the program worksheet. It tells me to calculate the monthly interest and i've been trying different ways to get it but i come up with different answers than what I supposed to get. Even my new balance has different answers.

Here's the program worksheet again (The output is at the bottom): http://faculty.winth...f12-savings.pdf


and here is my output code:
                 Savings Account Report


                        Thomas Powe
                         10-4-2012

              Previous                                                  New
   Account     Balance     Deposits    Withdrawals      Interest        Balance
      4523     4686.89       300.00         128.00          2.43        4858.89
      4567    12905.67        75.00          50.00         16.16       12930.67
      4658     1800.95         0.00           0.00          0.90        1800.95
      4677     1670.45      4200.00         650.00          2.61        5220.45
      4805    27531.82      2800.00        2000.00         41.32       28331.82
      4827    15963.45      2700.00         300.00         22.95       18363.45
      4868     1686.89      1150.00         300.00          1.27        2536.89


If someone can help me out with learning how to calculate the monthly interest, annual interest rate, etc (cause I have a hard time doing that), I will greatly appreciate it.
Was This Post Helpful? 0
  • +
  • -

#7 jimblumberg  Icon User is online

  • member icon


Reputation: 4293
  • View blog
  • Posts: 13,462
  • Joined: 25-December 09

Re: Savings Account Report Help

Posted 02 October 2012 - 02:00 PM

Quote

If someone can help me out with learning how to calculate the monthly interest, annual interest rate

It looks like the annual interest rate is contained in your file. That is why I asked what each column of your input file represented. It looks like it is in the following format:
Account number, yearly interest rate, balance, d,w, d,w, d,w.

Your assignment text tells you how to calculate the monthly interest rate:

Quote

3) For each month, calculate the monthly interest and add the monthly interest to the
balance. The monthly interest rate is the annual interest rate divided by twelve. To find
the monthly interest, multiply the monthly interest rate by the updated balance.


Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1