Question

I need to add two trivial functions to the following code. I am having an issue...

I need to add two trivial functions to the following code. I am having an issue with what i may need to change in the current code to meet the requirements. I am already displaying the bank record but now using a function

Here are some examples of what i can add to the code

1. Obtain opening (current) balance.

2. Obtain number the number of deposits.

3. Obtain number of withdrawals.

4. Obtain deposit amounts.

5. Obtain withdrawal amounts.

Output functions:

1. Display closing balance and associated message.

2. Display message based on closing balance.

3. Display bank record.


#include <stdio.h>
void main (void)
{


/* Declare variables */
/*-------------------*/
int num_deposit = 0, i, s;

int num_withdrawal = 0;

float current_balance;

float ending_balance;

float total_deposit = 0;

float deposit[5];

float withdrawals[5];

  


/* Intro and greeting to user. Allows starts the input sequence for the user */
/*---------------------------------------------------------------------------*/
printf("Welcome to the Computer Banking System \n\n");

printf("Enter your current balance in dollars and cents: ");

scanf("%f", &current_balance);

while(current_balance < 0)

{

printf("*** Beginning balance must be at least zero, please re-enter!");

printf("Now enter current balance in dollars and cents: ");

scanf("%f", &current_balance);

  

}

printf("\nEnter the number of deposits: ");

scanf("%d", &num_deposit);

  

while(num_deposit < 0||num_deposit>5)

{

printf("\n*** Invalid number of deposits must be at least zero,");

printf("please re-enter.\n");

printf("Enter the number of deposits: ");

scanf("%d", &num_deposit);

  

}

printf("\nEnter the number of withdrawals: ");

scanf("%d", &num_withdrawal);

while(num_withdrawal < 0||num_withdrawal>5)

{

printf("*** Invalid number of withdrawals must be at least zero,please re-enter.\n");

printf("Enter the number of withdrawals: ");

scanf("%d", &num_withdrawal);


  

}

for(i = 0; i < num_deposit; i++)

{

printf("\nEnter the amount of deposit #%d: ", i+1);

scanf("%f", &deposit[i]);

while(deposit[i]<0)

{

printf("*** deposit amount must be at least zero\n");

printf("please re-enter.\n");

printf("\nEnter the amount of deposit #%d: ", i+1);

scanf("%f", &deposit[i]);

}

total_deposit+=deposit[i];

  

}

for(i = 0; i < num_withdrawal; i++)

{

printf("\nEnter the amount of withdrawal #%d: ", i+1);

scanf("%f", &withdrawals[i]);

while(withdrawals[i]<0)

{

printf("*** withdrawal amount must be at least zero\n");

printf("please re-enter.\n");

printf("\nEnter the amount of withdrawal #%d: ", i+1);

scanf("%f", &withdrawals[i]);

}

if(withdrawals[i]>(current_balance+total_deposit))

{

printf("*** Withdrawal amount exceeds current balance. ***\n");
  

}

else

total_deposit -=withdrawals[i];

/* gives user their total, along with some financial advice or statements */
/*------------------------------------------------------------------------*/

}

ending_balance= current_balance+total_deposit;

printf("The closing balance is %.2f\n",ending_balance);
  
if(ending_balance>=50000)

printf("*** it is time to invest some money***\n");

else if(ending_balance>=15000)

printf("*** maybe you should consider a CD. ***\n");

else if(ending_balance>=1000)

printf("*** keep up the good work. ***\n");

else if(ending_balance>=0)
  
printf("*** your balance is getting low. ***\n");
  
/* Provides a bank record or statement. Providing totals*/
/*------------------------------------------------------*/

printf("***** Bank Record ******\n");

printf("Starting Balance $%.2f\n\n",current_balance);

for(i = 0; i < num_deposit; i++)

{

printf("Deposit #%d : $%.2f\n",i+1,deposit[i]);

}

printf("\n");

for(i = 0; i < num_withdrawal; i++)

{

printf("Withdrawal #%d : $%.2f\n",i+1,withdrawals[i]);

}

printf("\n");

printf("Ending balance :$%.2f\n",ending_balance);

printf("\n");

}


//end main

Homework Answers

Answer #1

// C program to implement Computer Banking System

#include <stdio.h>

// input functions
float getCurrentBalance();
int getNumberOfDeposits();
int getNumberOfWithdrawals();
float getDepositAmount(int i);
float getWithdrawalAmount(int i,float balance);

// output functions
void displayClosingBalanceAndMessage(float balance);
void displayBankRecord(float startingBalance, float currentBalance, int numOfDeposits, int numOfWithdrawals, float deposits[], float withdrawals[]);

void main(void) {

   /* Declare variables */
   /*-------------------*/
   int x, numberOfDeposits, numberOfWithdrawals;
   float deposits[5], withdrawals[5];
   float currentBalance, startingBalance;;
   float totalDeposits = 0, totalWithdrawals = 0;

   /* Intro and greeting to user. Allows starts the input sequence for the user */
   /*---------------------------------------------------------------------------*/
   printf("Welcome to the Computer Banking System.\n\n");
   currentBalance= getCurrentBalance();
   startingBalance = currentBalance;
   numberOfDeposits = getNumberOfDeposits();
   numberOfWithdrawals = getNumberOfWithdrawals();
   printf("\n");

   /* add the deposits entered */
   for (x = 1; x <= numberOfDeposits; x++)
   {

       deposits[x-1] = getDepositAmount(x);
       /* sum of total deposits */
       totalDeposits = totalDeposits + deposits[x-1];
   }

   currentBalance = currentBalance + totalDeposits;

   printf("\n");

   /* number of withdrawals */
   for (x = 1; x <= numberOfWithdrawals; x++)
   {
       /* total withdrawal sum */
       withdrawals[x-1] = getWithdrawalAmount(x,currentBalance);
       totalWithdrawals = totalWithdrawals + withdrawals[x-1];

       /* balance calculation */
       currentBalance = currentBalance - withdrawals[x-1];
       if (currentBalance == 0.00f)
       {

           /* zero balance error message */
           printf ("\n *** Balance is now zero. No more withdrawals can be made at this time. ***\n");
           numberOfWithdrawals = x;
           break;
       }
   }

   displayClosingBalanceAndMessage(currentBalance);
   displayBankRecord(startingBalance,currentBalance,numberOfDeposits,numberOfWithdrawals, deposits,withdrawals);

}

// function to get and return the current balance from user
float getCurrentBalance()
{
   float balance;
   do{
       /* prompts the user to enter current balance */
       printf ("Enter your current balance in dollars and cents: ");
       scanf ("%f",&balance);

       /* error message if current balance less than 0 */
       if (balance < 0)
           printf ("*** Beginning balance must be at least zero, please re-enter.\n");
   }
   /* this will end the loop if current balance is less than 0 */
   while (balance < 0);

   return balance;
}

// function to get and return the number of deposits from the user
int getNumberOfDeposits()
{
   int numOfDeposits;
   do
   {

       /* prompts for user to enter number of deposits */
       printf ("\nEnter the number of deposits (0 - 5): ");
       scanf ("%d",&numOfDeposits);

       /* a loop starts limiting the user on number of deposits */
       if (numOfDeposits < 0 || numOfDeposits > 5)
           printf ("*** Invalid number of deposits, please re-enter.\n");
   }
   /* if amount of deposits is between 0 and 5 loop will terminate */
   while (numOfDeposits < 0 || numOfDeposits > 5);

   return numOfDeposits;
}

// function to get and return the number of withdrawals from the user
int getNumberOfWithdrawals()
{
   int numOfWithdrawals;
   do
   {

       /* prompts user to enter number of withdrawals */
       printf ("\nEnter the number of withdrawals (0 - 5): ");
       scanf ("%d",&numOfWithdrawals);


       /* error message if amount is less than 0 or over 5 */
       if (numOfWithdrawals < 0 || numOfWithdrawals > 5)
           printf ("*** Invalid number of withdrawals, please re-enter.\n");
   }
   /* loop will terminate if amount is between 0 and 5 */
   while (numOfWithdrawals < 0 || numOfWithdrawals > 5);

   return numOfWithdrawals;
}

// function to get and return xth deposit amount from user
float getDepositAmount(int x)
{
   float amount;
   do
   {
       /* prompt to enter amount of each deposit */
       printf ("Enter the amount of deposit #%d: ", x);
       scanf ("%f",&amount);

       /* loop continues until amount is 0 or greater */
       if (amount < 0)
           printf ("*** Deposit amount must be at least zero, please re-enter.\n");
   }
   while (amount < 0);

   return amount;
}

// function to get and return xth withdrawal amount from user
float getWithdrawalAmount(int x, float balance)
{
   float amount;
   do
   {
       /* prompt for user to enter amount of each withdrawal */
       printf ("Enter the amount of withdrawal #%i: ", x);
       scanf ("%f",&amount);

       /* error message if withdrawal exceeds current balance */
       if (amount > balance)
           printf ("*** Withdrawal amount exceeds current balance.\n");
       else
           /* error message if amount is less than 0 */
           if (amount < 0)
               printf ("*** Withdrawal amount must be at least zero, please re-enter.\n");
   }
   /* loop ends when amount greater than 0 */
   while (amount > balance || amount < 0);

   return amount;
}

// function to display the closing balance and message depending on the closing balance
void displayClosingBalanceAndMessage(float balance)
{
   /* various final display messages */
   printf ("\n*** The closing balance is $%.2f *** \n", balance);

   if (balance >= 50000.00)
       printf ("*** It is time to invest some money! *** \n\n");
   else if (balance >= 15000.00)
       printf ("*** Maybe you should consider a CD. *** \n\n");
   else if (balance >= 1000.00)
       printf ("*** Keep up the good work! *** \n\n");
   else
       printf ("*** Your balance is getting low! *** \n\n");
}

// function to display all the details of the bank account, the starting balance, the transactions (deposit and withdrawal) and ending balance
void displayBankRecord(float startingBalance, float currentBalance, int numOfDeposits, int numOfWithdrawals, float deposits[], float withdrawals[])
{
   int x;
/* bank record */
   printf (" *** Bank Record ***\n");
   printf ("\nStarting Balance: $%.2f\n\n", startingBalance);
   for (x = 1; x <= numOfDeposits; x++)
   {
       printf ("Deposit #%x: %.2f\n", x, deposits[x-1]);
   }

   printf("\n");

   for ( x = 1; x<= numOfWithdrawals; x++)
   {
       printf ("Withdrawal #%i: %.2f\n", x, withdrawals[x-1]);
   }
   printf ("\nEnding Balance: $%.2f\n\n", currentBalance);

}

//end of program

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Construct a flowchart based on this code and write its equivalent algorithms. #include <stdio.h> int main()...
Construct a flowchart based on this code and write its equivalent algorithms. #include <stdio.h> int main() { int x,y; float result; char ch; //to store operator choice printf("Enter first number: "); scanf("%d",&x); printf("Enter second number: "); scanf("%d",&y); printf("Choose operation to perform (+,-,*,/): "); scanf(" %c",&ch); result=0; switch(ch) { case '+': result=x+y; break; case '-': result=x-y; break; case '*': result=x*y; break; case '/': result=(float)x/(float)y; break; case '%': result=x%y; break; default: printf("Invalid operation.\n"); } printf("Result: %d %c %d = %.2f\n",x,ch,y,result); // Directly...
Explain this code function by function in detail int menu() {   int choice;   do {     system("cls");...
Explain this code function by function in detail int menu() {   int choice;   do {     system("cls");     printf("1-Insurence Plan Subscription\n");     printf("2-Claim Processing\n");     printf("3-Accounts Information\n");     printf("4-Searching Functionalities\n");     printf("5-Exit\n");     scanf("%d", &choice);   } while (choice > 5 || choice < 1);   return choice; void subscribe() system("cls");   victims[userCount].id = userCount + 1;   printf("Enter age: ");   scanf("%d", &victims[userCount].age);   printf("\n\n%-25sHealth Insurence Plan\n\n", " ");   printf("-----------------------------------------------------------------------------------------------\n");   printf("|%-30s|%-20s|%-20s|%-20s|\n", " ", "Plan 120(RM)", "Plan 150(RM)", "Plan 200(RM)");   printf("-----------------------------------------------------------------------------------------------\n");   printf("|%-30s|%-20d|%-20d|%-20d|\n", "Monthly Premium", 120, 150, 200);   printf("|%-30s|%-20d|%-20d|%-20d|\n", "Annual Claim Limit", 120000,150000,200000);   printf("|%-30s|%-20d|%-20d|%-20d|\n",...
C++, I am not able to get this program to function correctly, ie not launching at...
C++, I am not able to get this program to function correctly, ie not launching at all #include <iostream> #include <stdio.h> int insert(int num, int location) { int parentnode; while (location > 0) { parentnode =(location - 1)/2; if (num <= array[parentnode]) { array[location] = num; return; } array[location] = array[parentnode]; location = parentnode; } array[0] = num; } int array[100], n; using namespace std; main() { int choice, num; n = 0; while(1) { printf("1.Insert the element \n"); printf("2.Delete...
Expand the code below to display both the value of the loop variable and this value...
Expand the code below to display both the value of the loop variable and this value squared. Put the pairs of values on a new line. #include <stdio.h> #include <stdlib.h> int main(void) { int i; int a; int b; do { printf("Please enter the lower value: "); scanf("%d", &a); printf("Please enter the upper value: "); scanf("%d", &b); if (a>b) printf("The upper value must be greater than the lower value\n\n"); } while (a>b); for(i=a; i<=b; i++) printf("%d ", i); return 0;...
Helllp plz Allow the InsertAt method to add to the front position 0 (zero) also if...
Helllp plz Allow the InsertAt method to add to the front position 0 (zero) also if you try to add to a position greater than the number of nodes you get an error warning. /INSERT.C /*THIS PROGRAM READS A BINARY FILE (MUST ALREADY EXIST AND BE FILLED) */ /*AND PUTS IT INTO A LINKED LIST AND PRINTS THE LIST TO THE SCREEN) */ #include #include #include #include typedef struct ENTRY { char name[81]; }ENTRY; typedef struct LISTREC /* LISTREC is...
int main() { while (1) { float d; scanf("%f", &d); float x; for (x = d;...
int main() { while (1) { float d; scanf("%f", &d); float x; for (x = d; x <= d + 1000.0; x = x + 1000.0) { } printf("loop exited with x = %.14g\n", x); } return 0; } If you run the program, you will see. What number should I use as an input to make this an infinite loop?
C CODE PLZ! Need all TO DO sections finished thanks #include <stdio.h> int main(int argc, char...
C CODE PLZ! Need all TO DO sections finished thanks #include <stdio.h> int main(int argc, char **argv) { const int BUF_LEN = 128; char str[BUF_LEN]; int i; char c; int is_binary; int d, n; /* Get the user to enter a string */ printf("Please enter a string made of 0s and 1s, finishing the entry by pressing Enter.\n"); for (i=0; i<BUF_LEN-1; i++) { scanf("%c", &c); if (c == '\n') { break; } str[i] = c; } str[i] = '\0'; /*...
How can i make this lunix code print 3 numbers in reverse it must be in...
How can i make this lunix code print 3 numbers in reverse it must be in printStars format and no loops Here is the code i have but can figure out how to reverse the numbers #include<stdio.h> void printStars(int n) { if (n>0){ printf(""); printStars(n-1); } } int main() { int n; int b; int c; printf("Enter 3 numbers to reverse "); scanf("%d",&n,&b,&c); printf("your reversed numbers are %d",n); printStars(n); return 0;
Design flow chart on software not handwritten. void claimProcess() {    int id;    bool found...
Design flow chart on software not handwritten. void claimProcess() {    int id;    bool found = false;    system("cls");       printf("Enter user ID for which you want to claim insurrence: ");    scanf("%d", &id);    int i;    for (i = 0; i < userCount; i++)    {        if (users[i].id == id)        {            found = true;            break;        }    }    if (found == false)   ...
Error compiler. need fix code for febonacci Iterative like 0 1 1 2 3 5 8...
Error compiler. need fix code for febonacci Iterative like 0 1 1 2 3 5 8 13 21 34 55 ....... and also need add code complexity time if you want! here code.c --------------------------------------------------------------------------------------------------------------------- #include <stdio.h> #include <math.h> int fibonacciIterative( int n ) { int fib[ n + 1 ]; int i; fib[ 0 ] = 0; fib[ 1 ] = 1; for ( i = 2; i < n; i++ ) { fib[ i ] = fib[ i -...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT