Class SavingsAccount compiles but doesn't show

I wrote a program that fit's my teacher's wants - it compiles, but it doesn't show anything I wrote except two cout I threw in to see where the program has gotten to. Maybe someone can see what I did wrong?

Teacher's direction:
1) The constructor initilizes the balance if greater than
0 and sets the other properties to 0.
2) If the transaction is greater than 0 then a Deposit is
made else a Withdraw is made.
3) The balance is increased with a deposit but decreased
if a Withdrawal. This assumes the Withdrawal is less than
the balance. Can't have a negative balance. Tell the user
that he is trying to make a withdrawal that exceeds his
balance.
4) When a WithDrawal is made increment FreqWithDraw else
if a Deposit is made increment FreqDeposit.
5) The toString procedure outputs all properties.
6) The total procedure tells you how much you will have in
savings given the interest rate and the amount of time.
Total(float savint,int time) returns Balance*(1+savint)^time.
Utilize a for loop for this calculation.
7) See if you can write a recursive procedure that does
the same thing as 6). Call it TotalRecursive.
8) Think of what follows as pseudocode. The random number
generator below produces a number between 0 and 32,767. If
you fashion a random number that will do the same then you
will get positive and negative transactions (-500,500).
The output simply calculates the current balance with a 10
percent interest rate and 7 years worth of compounding.
Also, you tried to start out with a negative balance which
should have been initialized to 0.


So my code is as follows:

savingsaccount.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//Saving Account
#ifndef SAVINGSACCOUNT_H
#define SAVINGSACCOUNT_H
#include <cmath>

using namespace std;

class SavingsAccount
{
private:
		float Withdraw(float);               //Utility Procedure
		float Deposit(float);                //Utility Procedure
		float Balance;                       //Property
		int   FreqWithDraw;                  //Property
		int   FreqDeposit;                   //Property
public:
		SavingsAccount(float bal) {Balance = bal;}               //Constructor
		void  Transaction(float trans)                           //Procedure
		{ while (Balance + trans >=0)
		{if (trans > 0){
            Balance =+ trans;
            FreqDeposit++;}
            else {
                 Balance =- trans;
                 FreqWithDraw++;}
                 } } 
		float Total(float savint,int time){                              //Savings Procedure
		Balance = Balance*pow(1+savint,time);
		return Balance;}
		float TotalRecursive(float savint,int time)
		{ for (int i = 0; i > time; i++){
             Balance = Balance*pow(1+savint,i);
             cout << "Savings for year " << i << ": $" << Balance << endl;
             } }
		void  toString()                     //Output Properties
		{ cout << "Balance: $" << Balance <<endl;
		  cout << "Number of withdrawls: " <<FreqWithDraw<<endl;
		  cout << "Number of deposits: " <<FreqDeposit<<endl;}
    };
    
    #endif 


and main.cpp code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <cstdlib>
#include <iostream>
#include "savingsaccount.h"

int main(int argc, char *argv[])
{
    cout << "Does this show? " << endl;
    
    SavingsAccount mine(-300);
    cout << "Does this show after making mine? " << endl;
	for(int i=1;i<=10;i++)
	{
		mine.Transaction((float)(rand()%500)*(rand()%3-1));
	}
	cout << "Does this show after making transactions? " << endl;
	mine.toString();
	cout << "Does this show after displaying all? " << endl;
	cout<<"Balance after 7 years given 10% interest = "
		<<mine.Total((float)(0.10),7)<<endl;
	cout << "Does this show after making total? " << endl;
	cout<<"Balance after 7 years given 10% interest = "
		<<mine.TotalRecursive((float)(0.10),7)
		<<" Recursive Calculation "<<endl;
		
    system("PAUSE");
    return EXIT_SUCCESS;
}


Thank you in advance <3
That class declaration is pretty hard to read with your coding style. Those brackets are all over the place. Try just keeping the function declaration inside the class declaration, and move the definition either to after the class declaration or to another file.
Last edited on
Topic archived. No new replies allowed.