1 Replies - 4587 Views - Last Post: 20 September 2011 - 08:19 PM Rate Topic: -----

#1 jmoz   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-September 11

Nested Loop for Compound Interest Problem

Posted 20 September 2011 - 07:56 PM

Hi, I'm having some difficulties trying to figure out how to do this with a nested loop.
#include <iostream>
using namespace std;
int main ()

{
    double deposit, ratein, rate, r1, r2; int i, j=0, years; char repeat;
    bool prompt;
    
    do
    {
         prompt = false;
         cout<<"Initial deposit? ";
         cin>>deposit;
         cout<<endl;
         cout<<"Interest rate in percentage? ";
         cin>>rate; 
         cout<<endl;
         cout<<"Number of years? ";
         cin>>years;
           
         while (years > 20)
         {
              cout<<"Enter number of years between 5 and 20: ";
              cin>>years;
         }   
         cout<<endl;
         
         if (years < 5) years = 5;
           
         rate = 1 + (ratein/100);
         r1 = rate - .1;
         r2 = rate + .1;
           
         for (i=1; i<=years; i++){
             cout<<i<<" "<<deposit<<endl;
             for (j; j<=i; j++){
                 deposit *= rate;
                 
             }
         }    
         cout<<"Would you like to try again? (Y/N) ";
         cin>>repeat;
         if (repeat == 'y' || repeat == 'Y') {
         prompt = true;
         }
         cout<<endl;
    } while (prompt);
     
    system("PAUSE");
    return 0;

}



I'm trying to do this without the pow operator. I get the years output correct but my initial deposit doesn't seem to be affected, it's not changing. I don't know how to go about trying to assign a new value to 'deposit' so that it equals the deposit amount times the interest for its respective amount of years and outputs the amount for each year. Thanks for any help.

Is This A Good Question/Topic? 0
  • +

Replies To: Nested Loop for Compound Interest Problem

#2 brds   User is offline

  • D.I.C Addict
  • member icon

Reputation: 76
  • View blog
  • Posts: 515
  • Joined: 22-October 08

Re: Nested Loop for Compound Interest Problem

Posted 20 September 2011 - 08:19 PM

What is the value of ratein?

0/100 = 0
1 + 0 = 1
??? * 1 = ???

This post has been edited by brds: 20 September 2011 - 08:20 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1