Help with get functions

I have my program, but I can get to work the getAPRCharge and getPayment() functions...Please help..!
Your goal is to create a program that calculates the finance charge and monthly payment on a certain balance of a credit card. You need to ask the user for the current balance of their card and call a function called getAPRCharge(). This function will return the APR charge using this formula: balance * 0.15 * 1/12. You will then call a function called getPayment to calculate the payment owed. If the balance is greater than $1000 then the payment will be (balance + APRcharge) * 0.05, if the balance is between 1000 and 100 then the payment will be (balance + APRcharge) * 0.01, and if the balance is less than 100 then the payment will just be balance + APRcharge. Finally you will print the balance, APR charge, and payment, and ask the user if they wish to run the program again. If they say yes then you will repeat, otherwise exit.
#include <iomanip>
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
//function prototype
float getPayment();
float getAPRCharge;
int main() {
string go_on = "yes";
while (go_on == "yes") {
float APRCharge = 0.0;
float balance = 0.0;
float newPayment;
float getAPRCharge;
cout << "How much is the current balance of your credit card?";
cout << endl;
cout << "$ ";
cin >> balance;
APRCharge =( balance * 0.15 * 1/12);
cout << "APR = "<< APRCharge << " %"<< endl;
if (balance > 1000) {
newPayment = (balance + APRCharge)* 0.05;
}
if ((balance >= 100) && (balance <= 1000)) {
newPayment = (balance + APRCharge)* 0.01;
}
if (balance < 100) {
newPayment = (balance + APRCharge)/ 12;
}
cout << "Your monthly payment will be: "<<"$"<< fixed << setprecision(2)<< newPayment<<endl;
void calcEndBalance();
cout <<"Do you wish to run the program again (\"yes\" or \"no\")? ";
cin >> go_on;
cin.ignore();
}
return 0;
}
You're pretty close actually. You need to calculate the APRCharge and newPayment in functions. Right now you're doing them in the program itself. So you want your main program to look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int main() {
    string go_on = "yes";
    while (go_on == "yes") {
	float APRCharge = 0.0;
	float balance = 0.0;
	float newPayment;
	float getAPRCharge;
	cout << "How much is the current balance of your credit card?";
	cout << endl;
	cout << "$ ";
	cin >> balance;
	APRCharge = getAPRCharge();
	cout << "APR = "<< APRCharge << " %"<< endl;
	newPayment = getPayment(balance, APRCharge);
	cout << "Your monthly payment will be: "<<"$"<< fixed << setprecision(2)<< newPayment<<endl;
	void calcEndBalance();
	cout <<"Do you wish to run the program again (\"yes\" or \"no\")? ";
	cin >> go_on;
	cin.ignore();
    }
    return 0;
}


Notice that getPayment takes two parameters.

You will need to change this
1
2
3
//function prototype
float getPayment();
float getAPRCharge;

to match the right function prototypes. Note that you currently declare getAPRCharge as a variable, not a function. To declare a function, it has to have the parentheses.

If you don't understand how to write a function then you should look that up in your class notes or textbook.

Thank you so much for your help and your time..!
I'm trying to implement the changes , but always I get errors.. like APRCharge()must have function type and balance as too many arguments in function call.

.
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
float getPayment();
float getAPRCharge();
int main() {
string go_on = "yes";
while (go_on == "yes") {
float APRCharge = 0.0;
float balance = 0.0;
float newPayment;
float getAPRCharge;
cout << "How much is the current balance of your credit card?";
cout << endl;
cout << "$ ";
cin >> balance;
APRCharge = getAPRCharge();
cout << "APR = "<< APRCharge << " %"<< endl;
newPayment = getPayment(balance, APRCharge);
cout << "Your monthly payment will be: "<<"$"<< fixed << setprecision(2)<< newPayment<<endl;
void calcEndBalance();
cout <<"Do you wish to run the program again (\"yes\" or \"no\")? ";
cin >> go_on;
cin.ignore();
}
return 0;
}
Topic archived. No new replies allowed.