Getting my program to print out users saving of every year not just the last year

Hello I writing a program that asks a user to input a deposit amount, the posting frequency, and how many years they plan to save. I am able to print out the final year, but I need to be able to print out the years in between the start date and the end date. I believe I have to use a for loop? Is this correct? Below is a sample of my code.

#include <iostream>
#include <math.h>

using namespace std;

int main()
{
double getinterest;
double rate;
double getdeposit;
int getyears;
double calcsavings;
int choice;
int payments;


getinterest = rate/100;

cout << "How much is your deposit each time? ";
cin >> getdeposit;

cout << "Make a choice how often you want to deposit." << endl
<< "\t1. Yearly\n" << "\t2. Half Year\n"
<< "\t3. Quarterly\n" << "\t4. Monthly\n" << endl
<< "Make your choice: ";
cin >> choice;

if(choice == 1){
cout << "Enter the interest rate: ";
cin >> rate;

cout << "For how many years? ";
cin >> getyears;

payments = 1;
getinterest = rate/100;

calcsavings = getdeposit*((pow((1+(getinterest/payments)), payments*getyears)-1)/(getinterest/payments));
cout << "Your savings are " << calcsavings;


}
First of all, please surround your code with the [code ][ /code] (Remove the spaces)tags, it makes things much easier to read.

As for the code, yes, you will need a for loop.
Last edited on
Topic archived. No new replies allowed.