C and Cpp

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsDesktop ProgrammingC and Cpp

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old September 15th, 2007, 11:33 PM
veronicak5678 veronicak5678 is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Sep 2007
Posts: 1 veronicak5678 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 43 sec
Reputation Power: 0
Compound Interest Formula

I can't seem to figure this out, though it should be pretty simple. Here are my instructions:
Compound interest

Compound.cpp

Write a program that calculates compound interest. The program should ask the user for the starting dollar amount and the daily increase (as a percentage), and the number of days. A loop should then be used to display the day, the amount of interest earned on that day and the account balance on that day. The program should also display the total interest earned. Output should be as follow



Initial amount in dollars? 100
Interest rate in percentage? 10
Number of days? 3




Day Earned interest Balance
-----------------------------------------------
1 $10 $110.00
2 $11 $121.00
3 $12.10 $133.10

Total Interest earned: $33.10


Validation:
Dollar amount should be between 10 and 10000
Interest rate should be between 1 and 22
Number of days should be between 2 and 30

The output should be formatted and aligned according to the above.


Here is my code:


Code:



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

using namespace std;

int main ()
{
double dollars, amount, interest, power, formularate; 
int days, rate;
bool notValid;
int a=1;
   
   do{
   notValid=false;                                       //Validation for amount
   cout << "\nPlease enter dollar starting amount?" ; 
   cin >> dollars;
   if (dollars <10 || dollars >10000)
       {
        cout << "\nYou have entered invalid data"; 
        notValid=true;
        }
   } while (notValid);

   do{
   notValid=false;                                       //Validation for rate
   cout << "\nWhat is the daily increase (as a percentage)?" ;
   cin >> rate;
   if (rate <1 || rate >22)
       {
        cout << "\nYou have entered invalid data"; 
        notValid=true;
        }
   } while (notValid);
  
   do{
   notValid=false;                                       //Validation for days
   cout << "\nEnter the number of days:" ;
   cin >> days;
   if (days<2 || days >30)
       {
        cout << "\nYou have entered invalid data"; 
        notValid=true;
        }
   } while (notValid);
  
   {
       cout << "\n\nDay     Earned Interest     Balance"; 
       cout << "\n-----------------------------------\n";
        
       
        for(a==1; a <= days; )                           //Loop for display 
                { 
                  formularate=(rate/100);
                  amount=dollars*pow(1+(formularate/365),(a));
                  interest=amount-dollars;                     
                  cout << a;
                  cout << "           ";  
                  cout << interest; 
                  cout << "               "; 
                  cout << amount;  
                  cout << "               "; 
                  cout <<"\n\n";                  
                  a++;                                                     }      
            system("pause");
            

    }
}

Why is my interest 0?

Reply With Quote
Reply

Viewing: Tutorialized ForumsDesktop ProgrammingC and Cpp > Compound Interest Formula


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap