Write a program that allows users to enter a dollar amount for their bank accoun
ID: 3551769 • Letter: W
Question
Write a program that allows users to enter a dollar amount for their bank account balance at the beginning of the month. Then ask the user to enter a dollar amount for any number of checks written in a month, up to 50. Include an approriate sentinel value that the user can enter to stop enter checks. Store the amounts in an array and count the entries as the user makes them. Finally ask the user to enter a monthly interest rate if the account is interest bearing, or 0 if it is not. If the user enters 0 for the interest rate, than call a function named balanceAccount() that accepts the beginning balance, the number of checks, and the array of check amounts as parameters; the function displays the final balance after all checks have been subtracted from the beginning balance. If the user enters a number other than 0 for the interest rate, then call an overloaded function named balanceAccount() that accepts the beginning balance, the number of checks, the array of check amounts, and the interest rate as parameters. This function then computes the final balance by subtracting all the checks from the beginning balance and using the monthly interest rate to increase the final balance before displaying it.
Please only use things that would have been learned in the first 6 chapters of the book mentioned above. Please dont use code that we have not learned about. Points will be awarded promptly as long as it is correct format correct code and runs correctly.
Explanation / Answer
Dropbox-link:
https://dl.dropboxusercontent.com/u/78383401/chegg/balance.cpp
__________________________________________________________________
Code:
#include<stdio.h>
#include <iostream>
using namespace std;
//balanceAccount() that accepts the beginning balance, the number of checks, and the array of check amounts as parameters
void balanceAccount(float int_balance, int checks, float* check_arr){
float finalbalance=int_balance;
for(int i=0; i<checks; i++){
finalbalance = finalbalance - check_arr[i];
}
cout<<"Final balance in your account is: "<<finalbalance<<"$"<<endl;
}
void balanceAccount(float int_balance, int checks, float* check_arr, float rate){ //overloaded function
float finalbalance=int_balance;
for(int i=0; i<checks; i++){
finalbalance = finalbalance - check_arr[i];
}
//adding interest to the finalbalance
finalbalance=finalbalance+(finalbalance*rate*1/100);
cout<<"Final balance in your account is: "<<finalbalance<<"$"<<endl;
}
int main(){
float int_bal,check_arr[50]={0};
float amount,rate;
int checks=1,i=0;
cout<<"Enter initial amount"<<endl;
cin>>int_bal;
cout<<"Enter dollar amount for upto 50 checks, enter -100 for stopping"<<endl; //-100 is sentinel value
cin>>amount;
while(amount!=-100 && checks<=50){
check_arr[i]=amount;
i++;checks++;
cin>>amount;
}
cout<<"Enter monthly interest rate if the account is interest bearing otherwise 0"<<endl;
cin>>rate;
if(rate==0){
balanceAccount(int_bal,checks,check_arr);
}
else{
balanceAccount(int_bal,checks,check_arr,rate);
}
return 0;
}
_______________________________________________________________________________________
Output:
With no interest:
With interest:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.