Decimal point precision, "Headings", and "Parameters"

(1) I'm wondering how to set the decimal point precision for individual variables. In the program I wrote, I set everything to two-decimal point precision. I want it to be 2-point precision for the monetary values, and 0-point (no decimals) for variables like "number of payments." How do I do that? Here is my code:

// This is a program for the monthly payment on a loan,
// that is calculated by the formula,
// Payment = Rate * (1+Rate)^N / ((1+Rate)^N - 1) * L
// Rate is the monthly interest rate, which is annual interest rate divided by 12. (12% annual interest would be 1 percent montly interest).
// N is the number of payments and L is the amount of the laon.
// The program asks the user for these values (Rate, N, and L) for two different situations and displays a report similar to:
// Loan amount: $ L
// Monthly Interest Payment: Rate%
// Number of Payments: N
// Monthly Payment: $ xxx.00
// Amount Paid Back: $ xxx.00 --- we don't know this information.
// Interest Paid: $ xxx.00 --- we don't know this information, either.

// a. Write pseudocode to detail your problem solution
// b. write a program.

#include <iostream> // these parts include the libraries necessary to use
#include <cmath>
#include <iomanip>

using namespace std;

int main ()
{
double Rate, Payment, N, L;

cout << "Hello. Please input the rate of your loan:";
cin >> Rate;
cout << "Plese input the number of payments:";
cin >> N;
cout << "Please input the amount of your loan:";
cin >> L;

Payment = Rate * pow (1+Rate, N) * L /( pow (1+Rate,N) - 1) ;

cout << setprecision (2) << fixed;

cout << "Thanks." << endl <<
"Loan amount: $"<<L<<endl <<
"Monthly Interest Payment: "<<Rate<<"%"<<endl<<
"Number of Payments: "<<N<<endl<<
"Monthly Payment: $"<<Payment<<endl;

system ("pause");
return 0;
}


======================================…

(2) I have these instructions from my instructor, and I have no idea what she's asking. The instructions, I copied out of a pdf into comment form in CSS and I'll just copy and paste from there: (quote)

// Modify problem 2 so that it includes
// a user defined function by the name of paymentCalc.
// paymentCalc should have a heading of:
// paymentCalc(double loanAmt, double rate, int numPayments)
// The program should ask for the 3 values and send them to paymentCalc as parameters.
// paymentCalc should calculate the necessary information and display a report like that in problem 2.
// a. modify your pseudocode to illustrate your 2 functions (main and paymentCalc)
// b. Write a program
9 minutes ago - 4 days left to answer.
Additional Details
in (2), specifically, I don't know what she means by a heading. I don't know what "paymentCalc(double loanAmt, double rate, int numPayments)" means, where it would be in the program, what it is, or anything...

I also don't know what parameters are. =\
The heading, I'm assuming would be the function definition, which would go before your main() function. It would look something like:
double paymentCalc(double loanAmt, double rate, int numPayments);

As far as the precision thing goes, add << resetiosflags(ios::fixed) << in your cout statement, before the number you no longer want to be effected by the setprecision().

Also, parameters are the variables sent to a function that you are calling. So you want to call paymentCalc() to calculate the information you need; rate, N and L will be your parameters.


Topic archived. No new replies allowed.