|
-
July 14th, 2011, 03:24 PM
#17
Re: Loop Problem
 Originally Posted by GCDEF
You changed your code since your OP. I still get two warnings with VC2008 with the code you currently have.
You're still passing a double as an int apparently.
(110) : warning C4244: 'argument' : conversion from 'double' to 'int', possible loss of data
(73) : warning C4715: 'PaymentSelection' : not all control paths return a value
Does this fix it?
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(double total)
{
return (total*MinInterest);
}
//User Selects Set Ammount Or Minimum Payment Style
double PaymentSelection(double 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;
}
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
|