A
atreide_son
hello all...
yes i'm a newbie and i need help.
i have an assignment due for class, but I don't know i'm stuck and
can't get out from under myself.
here's the focus of the program:
Write a C program that allows the user to make some simple banking
transactions. The program should first prompt the user to enter the
current balance of his/her bank account (in dollars and cents). The
program should then prompt the user to enter the number of deposits to
make, and then the number of withdrawals to make.
Using a loop, the program should then prompt the user to enter the
amount of the first deposit (to add to the bank account balance), the
amount of the second deposit, the third, & etc., until the number of
deposits have been processed.Using a second loop, the program should
then prompt the user to enter the amount of the first withdrawal (to
subtract from the bank account balance), the amount of the second
withdrawal, the third, & , etc. until the number of withdrawals have
been processed.Once all deposits and withdrawals have been made, the
program should output the ending balance.
The dialog with the user should look like:
Welcome to the Sears Bank Balancing SystemEnter
Enter current balance in dollars and cents: 256.40
Enter the number of deposits: 3
Enter the number of withdrawals: 2
Enter the amount of deposit #1: 10.50
Enter the amount of deposit #2: 12.25
Enter the amount of deposit #3: 125.30
Enter the amount of withdrawal #1: 120.35
Enter the amount of withdrawal #2: 35.60
*** The closing balance is $248.50 ***
At this point, the program should also output one of the following
messages based on the closing balance.
If the closing balance is greater than or equal to 5000.00, output:
"*** Time to invest some money! ***"
If the closing balance is between 2000.00 and 4999.99, output:
"*** Maybe you should consider a CD. ***"
Regarding error checking on user input, the following check should be
made while users are entering the withdrawal amounts:
If the withdrawal amount exceeds the current balance(including the new
deposits), the program should issue the following error message: ***
Withdrawal amount exceeds current balance. ***The program should then
re-prompt for a lower withdrawal amount, so not to go below current
balance amount. But, if the current balance goes to zero, no more
withdrawals should be made and an appropriate message should appear.
Here's what I have so far on my own:
#include <stdio.h>
main ()
{
/* Declaration of Variables */
int x;
int num_dep;
int num_with;
float total_dep = 0;
float initial_balance, running_bal;
float withdrawal, total_with = 0;
/* */
printf ("\nWelcome to the Milas Bank Balancing System \n");
/* Begin by asking the user to enter the amount of the deposit */
printf ("\nEnter current balance in dollars and cents: ");
scanf("%f", &initial_balance);
fflush(stdin);
printf ("\nEnter the number of deposits: ");
scanf("%f", &num_dep);
fflush(stdin);
printf ("\nEnter the number of withdrawals: ");
scanf("%f", &num_with);
fflush(stdin);
running_bal = total_dep + initial_balance;
total_dep = running_bal + initial_balance;
/* Prompt user for Deposit Amounts */
for (x = 1; x <= total_dep; x++)
if ( total_dep < 0 )
{
printf ("*** Withdrawal amount exceeds current
balance. ***\n");
x--; /* decrement counter to stay at same grade entry */
fflush(stdout);
}
else
/* end if-else */
} return 0;
} // end main
yes i'm a newbie and i need help.
i have an assignment due for class, but I don't know i'm stuck and
can't get out from under myself.
here's the focus of the program:
Write a C program that allows the user to make some simple banking
transactions. The program should first prompt the user to enter the
current balance of his/her bank account (in dollars and cents). The
program should then prompt the user to enter the number of deposits to
make, and then the number of withdrawals to make.
Using a loop, the program should then prompt the user to enter the
amount of the first deposit (to add to the bank account balance), the
amount of the second deposit, the third, & etc., until the number of
deposits have been processed.Using a second loop, the program should
then prompt the user to enter the amount of the first withdrawal (to
subtract from the bank account balance), the amount of the second
withdrawal, the third, & , etc. until the number of withdrawals have
been processed.Once all deposits and withdrawals have been made, the
program should output the ending balance.
The dialog with the user should look like:
Welcome to the Sears Bank Balancing SystemEnter
Enter current balance in dollars and cents: 256.40
Enter the number of deposits: 3
Enter the number of withdrawals: 2
Enter the amount of deposit #1: 10.50
Enter the amount of deposit #2: 12.25
Enter the amount of deposit #3: 125.30
Enter the amount of withdrawal #1: 120.35
Enter the amount of withdrawal #2: 35.60
*** The closing balance is $248.50 ***
At this point, the program should also output one of the following
messages based on the closing balance.
If the closing balance is greater than or equal to 5000.00, output:
"*** Time to invest some money! ***"
If the closing balance is between 2000.00 and 4999.99, output:
"*** Maybe you should consider a CD. ***"
Regarding error checking on user input, the following check should be
made while users are entering the withdrawal amounts:
If the withdrawal amount exceeds the current balance(including the new
deposits), the program should issue the following error message: ***
Withdrawal amount exceeds current balance. ***The program should then
re-prompt for a lower withdrawal amount, so not to go below current
balance amount. But, if the current balance goes to zero, no more
withdrawals should be made and an appropriate message should appear.
Here's what I have so far on my own:
#include <stdio.h>
main ()
{
/* Declaration of Variables */
int x;
int num_dep;
int num_with;
float total_dep = 0;
float initial_balance, running_bal;
float withdrawal, total_with = 0;
/* */
printf ("\nWelcome to the Milas Bank Balancing System \n");
/* Begin by asking the user to enter the amount of the deposit */
printf ("\nEnter current balance in dollars and cents: ");
scanf("%f", &initial_balance);
fflush(stdin);
printf ("\nEnter the number of deposits: ");
scanf("%f", &num_dep);
fflush(stdin);
printf ("\nEnter the number of withdrawals: ");
scanf("%f", &num_with);
fflush(stdin);
running_bal = total_dep + initial_balance;
total_dep = running_bal + initial_balance;
/* Prompt user for Deposit Amounts */
for (x = 1; x <= total_dep; x++)
if ( total_dep < 0 )
{
printf ("*** Withdrawal amount exceeds current
balance. ***\n");
x--; /* decrement counter to stay at same grade entry */
fflush(stdout);
}
else
/* end if-else */
} return 0;
} // end main