#include<iostream> #include<cmath> using namespace std;
struct BankAccount {
double balance;
double interestRate;
};
// get data from the user
void getData(BankAccount& account);
// calculate the interest
double interest(BankAccount account, int year);
// display the information
void display(BankAccount account);
int main() {
// magic formula
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
BankAccount myAccount; // declare a BankAccount getData(myAccount); // get data display(myAccount); // display int year = 2; cout << "The interest of your account is " << interest(myAccount, year) << " after " << year << " years.\n"; return 0; }
void getData(BankAccount& account) { cout << "Enter account balance: "; cin >> account.balance; cout << "Enter account interest rate: "; cin >> account.interestRate; }
double interest(BankAccount account, int year) { return account.balance*pow(1+account.interestRate,year) - account.balance; }
void display(BankAccount account) { cout << "Balance: " << account.balance << endl; cout << "Interest Rate: " << account.interestRate << endl; }
|