I am not sure what I am doing here, I was given a formula to use in the passing by reference and my lecture was not helpful at all. I am also supposed to put this in a loop so that someone can keep entering until they terminate the program..
> I was given a formula to use in the passing by reference and my lecture was not helpful at all.
> I am also supposed to put this in a loop so that someone can keep entering until they terminate the program..
Before you make it a function, before you make it a loop - just try to do it once in main().
Make something small that goes some way to solving the problem.
Then you have something to build on.
Sorry about that, first time I posted on here... I am trying to pass this class and I am struggling with this, my teacher isn't very helpful.. this is what he is looking for
Without using global variables, write a C++ program that contains a function (other than main() function) that calculates the monthly payment of a mortgage. The function will receive (will have inputs) loan amount, annual interest rate, and the term (the number of years to pay off the loan), and returns the monthly payment, total payment, and the total interests paid. Do not include any cin nor cout statements inside of the function, in other words, the function don't display any calculation results, it returns calculation results, such as monthly payment, total payment, and the total interests paid to the caller. The caller function will display the calculation results. (Make sure no calculation made in main() function, the main() receives the calculation results from the function calls and displays those results on the screen).
More specifically, in the main() function, using a a looping statement to allow a user to repeatedly use the function for the calculation.
Understanding compiler error messages is a skill that will go a long way. Read them and try to guess what they mean. If you still aren't sure, post the compiler error message and just tell us your guess as to what it means, then we can tell you how far off you are.
Line 21: you are attempting to call functionA, but the variable 'z' does not exist in the main function. Non-global variable names in different functions have separate scope.
Furthermore, you attempt to use like half a dozen variables that don't exist in functionA. What is A? What is s? etc.
If x in functionA is supposed to be the same variable as the x in main, you must pass that by reference, too
1 2 3 4 5 6 7
void functionA(int& a, int& x)
{ ... }
// main
int a:
int x; // etc.
functionA(a, x);
Without any restrictions, write a C++ program to compute the monthly payment of one mortgage.
This is the essence of your computer program, the most important bit of functionality. It is also the hardest part of your task, one that you should solve before adding superfluous restrictions.
1 2 3 4 5 6 7 8 9 10 11 12
#include <iostream>
usingnamespace std;
int main()
{
// enter loan principal, interest rate, and term; then
// compute monthly payment; then
// print monthly payment
// your code here
}
Once you have this, you can focus on making sure that all of the assignment's requirements are satisfied, one at a time.
move the functionA(R, TotalPayement etc?
or I believe its what goes in the void functionA()<----?
I also added the while statement in there to make it loop
#include<iostream>
#include<cmath>
usingnamespace std;
void functionA()
{
x = r / 1200;
y = 1 - (pow(1 + x, -12 * t));
R = A / (y / x);
TotalPayment = R * (12 * t);
TotalInterestPaid = TotalPayment - A;
}
int main()
{
int a = 1;
int TotalInterestPaid;
int TotalPayment;
double A, r, t;
double R, x, y;
while (a == 1) {
cout << "Please Enter The Loan Amount:\n";
cin >> A;
cout << "Please Enter the Interest Rate:\n";
cin >> r;
cout << "Please Enter the Number of Years:\n";
cin >> t;
functionA(R, TotalPayment, TotalInterestPaid);
cout << "Your Monthly Payment is" << "$" << R << endl;
cout << " Your Total Payment is" << "$" << TotalPayment << endl;
cout << "Total Interest paid is" << "$" << TotalInterestPaid << endl;
cout << "===================================================================" << endl;
cout << "Please enter 1 to continue, or any other number to end the program:" << endl;
cin >> a;
}
return 0;
}
> I also added the while statement in there to make it loop
You should have fixed the first problem of making it work once, using a function with reference parameters.
Not add more code to something that doesn't work.
You already know what a reference parameter looks like from your first post.
void functionA(int x, int, int r, int y, int x, int t, int R, int A, int TotalPayment, int TotalInterestPaid) ?? i imagine its int & something for pass by reference?