can't find where the error occurs using debugger? any help plz~~

//this program computes how much money will
//accumulate after so many years of investing

#include <iostream>
using namespace std;

float Balance = 0.0;
float Interest;
float YearlyCont;
int NumYears;

//this function computes one year of investment
float newBalance(float balance);

int main () {
    cout << "How much money will you deposit" << "each year?" << endl;
    cin >> YearlyCont;

    cout << "What interest rate will you get" <<"(enter 5% as .05)?" << endl;
    cin >> Interest;

    cout << "How many years will you invest?" << endl;
    cin >> NumYears;

    for (int i = 1; i <= NumYears; i++);
    Balance = newBalance (Balance);

    cout << "Money at end of investment: " << Balance << endl;

    return 0;
}

float newBalance (float balance) {

//add in this year's deposit
balance = balance + YearlyCont;

//add in this year's interest
balance = (Interest + 1.0f) * Balance;

return balance;
}

Recommended Answers

All 2 Replies

You've just discovered your first reason to dislike global variables!

balance = (Interest + 1.0f) * Balance;

oh! i c...thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.