I'm having a hard time understanding how to use pointers. In my code below I an computing the compounded quarterly interest (5.3%) on a given savings account balance. I can get the first quarter values but am stuck on the second and subsequent values . Yes, homework.
Code:
/* This program will read a given savings account balance input by the user and calculate
quarterly interest. It will print quarterly and yearly interest earned, beginning and ending savings balances
in columned format with appropriate headings.
Written by Patricia Stephens
Date: June 2009
*/
#include "stdafx.h"
#define interest_rate .053
//Function Declarations
void getData(float* beg_balance);
float multiply(float beg_balance);
float add(float beg_balance, float earned_interest);
void printRes(float earned_interest,float new_balance);
int main(void)
{
// Local Declarations
float beg_balance;
float earned_interest;
float new_balance;
// Statements
getData(&beg_balance);
earned_interest = multiply(beg_balance);
new_balance = add(beg_balance,earned_interest);
printRes(earned_interest, new_balance);
return 0;
} // main
/* ===================================getData=============================
This function reads the savings balance input by the user at the keyboard
Pre parameter save balance is an address
Post Data read into parameter address
*/
void getData(float* beg_balance)
{
//statements
printf("Please Enter your savings account balance: \n");
scanf_s("%f", beg_balance);
return ;
} //getData
/*====================================multiply=============================================
this function will calculate the quarterly interest on a given savings amount
pre float beg_balance sav_balance & earned_interest are variables where values to be calculated will be stored
post value in end_balance will be stored
*/
float multiply(float beg_balance)
{
//local declarations
float earned_interest;
//statements
earned_interest = (beg_balance * interest_rate);
//printf("**multiplyYou earned $%8.2f this month\n", earned_interest);
//printf("**multiplyYou earned $%8.2f for the second quarter\n", second_quarter_interest);
return earned_interest;
} //multiply
/* ==================================add=============================================
this function will add beg_balance to earned interest and print results
pre interest_earned and sav_balance contain variables
post print new balance
*/
float add (float beg_balance, float earned_interest)
{
//local definitions
float new_balance;
//Statements
new_balance = beg_balance + earned_interest;
//printf("**addYOur new balance is $%8.3f\n", new_balance);
return new_balance;
}
/* =================================printRes=======================================
Print Savings Balance
Pre beg_balance contains number to be printed
Post value in sav_balance printed*/
void printRes(float earned_interest, float new_balance)
{
//Statements
printf("\t\t\Interest Earned\t\t\t\t New Balance\n");
printf("First Quarter: $%8.2f\t\t\t\t$%8.2f\n", earned_interest, new_balance);
//printf("**printYou earned $%8.2f\n in interest this month\n", earned_interest);
//printf("**printYour new balance is $%8.2f\n", new_balance);
//printf("**printYour second quarter earnings are $%8.2f\n", second_quarter_interest);
return;
} //printRes