|
-
July 14th, 2011, 02:19 PM
#1
Loop Problem
I am in college for programming, but my programming classes do not start until January. I am trying to work on C++ to get ready for my classes. I am currently in Personal Finance class and was intrigued by an interest calculator. I am not done the code because I need to add the compound interest section in the final loop. The problem I can't seem to fix is updating the minimum payment after each monthly payment. I also need to section off the part that chooses a set payment or a minimum payment. I just wanted to point out I am aware of this and know I need to fix it.
The problem: If I add payment=total*MinInterest(this is defined as .03 for 3% then the loop gets stuck. I also used the math::ceil() for the wrong reason. I was trying to find a way to trim the double variables down to two decimal places(0.00) Can someone explain why I am having the loop problem and what I need to work on as far as code. I take all your advice very seriously and am anxious to learn. Here is the code.
BTW I am using DEV-C++
Code:
#include <cstdlib>
#include <iostream>
#include "math.h"
#define year 12
#define MinInterest .03
#define DaysInCycle 30
using namespace std;
// Displays Program Header
void menu()
{
cout<<"@@@@@@@@@@@@@@@@@@@@\n"
<<"@ @\n"
<<"@ Credit @\n"
<<"@ Card @\n"
<<"@ Payoff @\n"
<<"@ Calculater @\n"
<<"@ @\n"
<<"@@@@@@@@@@@@@@@@@@@@\n";
}
//Gets Bill Total
double bill_total()
{
double total;
system("CLS");
menu();
cout<<"Please Enter The Total Amount:";
cin>>total;
total=ceil(total);
return total;
}
// Gets APR
double APR()
{
system("CLS");
menu();
double APR;
cout<<"Please Enter APR:";
cin>>APR;
APR=ceil(APR);
return APR;
}
//Gets User's Payment If PaymentSelection == 2
double GetPayment()
{
double ammount;
system("CLS");
menu();
cout<<"Please Enter Payment Ammount:";
cin>>ammount;
return ammount;
}
//Calculates Minimum Payment
double CalculateMinPayment(int total)
{
return (total*MinInterest);
}
//User Selects Set Ammount Or Minimum Payment Style
double PaymentSelection(int total)
{
int choice;
do{
system("CLS");
menu();
cout<<"1.Minimum Payment 2.Set Payment\n";
cin>>choice;
if(choice==1)
return CalculateMinPayment(total);
else if(choice==2)
return GetPayment();
}while(choice!=1||choice!=2);
}
//Finale Calculation
void calculate(double APR,double Payment,double Total)
{
//initilize
double TotalInterest=0,MonthlyInterest=0,Principal=0,AverageDailyBalance=0,TotalPaid=0;
double month=1.0;
//loop tell total is paid
while(Total>0){
//calculate monthly APR
APR=ceil(APR);
//calculate monthly interest
MonthlyInterest=(APR/year)/100;
//calculate Average Daily Balance
AverageDailyBalance=Total/DaysInCycle;
//Find Total Interest Paid
TotalInterest=AverageDailyBalance*MonthlyInterest;
//round total interest
TotalInterest=ceil(TotalInterest);
//Calculate principal paid
Principal=(Payment-TotalInterest);
//Calculate total for next month bill
Total=(Total-Principal);
//Keep track of total paid
TotalPaid=TotalPaid+Payment;
month++;}
system("CLS");
cout<<"It will take you "<<(month/12)<<" years to pay off the ammount.\n";
cout<<"And it will cost you "<<TotalPaid<<"$"<<" total\n";
}
int main(int argc, char *argv[])
{
menu();
double total=bill_total();
calculate(APR(),PaymentSelection(total),total);
system("PAUSE");
return EXIT_SUCCESS;
}
Last edited by josh26757; July 14th, 2011 at 02:45 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|