Thanks for the info. I have recoded my program to this
Code:
#include <cmath>
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
double payment;
double loan;
double rate;
double nPayments;
double mathRate;
bool valid;
printf("%50s","William's Loan Service\n");
do {
valid=true;
printf("\n Please enter the loan amount. ");
scanf("%lf",&loan);
if (loan < 100 || loan > 999999.99)
{
printf("\n Loan amount must be between $100.00 and $999,999.99\n");
valid=false;
}
}while (!valid);
do {
valid=true;
printf("\n Please enter annual interest rate. ");
scanf("%lf",&rate);
if (rate < 1 || rate > 20)
{
printf("\n The interest rate must be between 1 and 20\n");
valid=false;
}
}while (!valid);
do {
valid=true;
printf("\n Please enter the number of payments. ");
scanf("%lf",&nPayments);
if (nPayments < 5 || nPayments > 360)
{
printf("\n The number of payments must be between 5 and 360\n");
valid=false;
}
}while (!valid);
mathRate = rate/1200;
payment = (mathRate*pow((1+mathRate),nPayments)/(pow((1+mathRate),nPayments)-1))*loan;
printf("\n Loan Amount: $ %9.2lf\
\n Annual Interest rate: %9.lf\
\n Number of Payments: %9.lf\
\n Monthly Payments: $ %9.2lf\
\n Amount Paid Back: $ %9.2lf\
\n Interest Paid: $ %9.2lf\
\n", loan,rate,nPayments,payment,(payment*nPayments),((payment*nPayments)-loan));
system("pause");
}
Asthetically my program looks just like the example. Is this the standard way to format the display? The issue is that I am new to C and I have an instructor who is, to put it nicely, very cryptic. his instructions were literally:
"• Validate all user entry. If no range is specified then the entry must be greater than 0.
• You must use the proper kind of loops for validation
• Make sure that your display is formatted correctly
Validation:
Loan amount should be between $100 and $999,999.99
Interest rate should be between 1 % and 20%
Number of payments should be between 5 and 360 months
The report should be formatted and aligned according to the above"
I am most concerned about the final printf. is that considered "proper"?