Code:
#include <stdio.h>
#define ANNUM .035
int main(){
int month, days_in_month, day=1;
int count_credit=0, count_debit=0;
int newday;
int option;
float current_bal, new_balance;
float balance = 2000;
float deposit, total_one, total_d;
float withdraw, total_w, total_two;
float min_bal=balance;
float interest, final;
printf("Enter the transaction month (1-12):\t");
scanf("%d", &month);
while(month>12 || month <1){
printf("Please enter a valid month (1-12):\t");
scanf("%d", &month);
}
switch(month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days_in_month=31;
printf("Number of days in this month:%d\t\n", days_in_month);
break;
case 4:
case 6:
case 9:
case 11:
days_in_month=30;
printf("Number of days in this month:%d\t\n", days_in_month);
break;
case 2:
days_in_month=28;
printf("Number of days in this month:%d\t\n", days_in_month);
break;
}
printf("\nYour balance is: $%.2f\n\n", balance);
while(option!=4){
//the list of transactions
printf("Transaction options: \n");
printf("1 - Deposit funds (credit transaction) \n");
printf("2 - Withdraw funds (debit transaction) \n");
printf("3 - Print statement of account \n");
printf("4 - Compute interest and exit \n");
printf("Please indicate your option:\t");
scanf("%d", &option);
//if option one was selected
if(option==1){
printf("Please enter a valid date from %d to %d\t", day, days_in_month);
scanf("%d", &newday);
while(newday > days_in_month || newday <day){
printf("Please enter a valid date from %d to %d\t", day, days_in_month);
scanf("%d", &newday);
}
printf("\n How much do you want to deposit?\t");
scanf("%f", &deposit);
balance+=deposit;
printf("Your balance is:\t $%.2f\n\n", balance);
count_credit++; // counts credit transactions
day=newday;
}
//end of option one
else if (option==2){ //if option 2 was selected
printf("Please enter a valid date from %d to %d\t", day, days_in_month);
scanf("%d", &newday);
while(newday > days_in_month || newday <day){
printf("Please enter a valid date from %d to %d\t", day, days_in_month);
scanf("%d", &newday);
}
printf("\n How much do you want to withdraw?\t");
scanf("%f",&withdraw);
current_bal=balance;
current_bal-=withdraw;
while(current_bal<0){
new_balance=balance;
printf("Sorry, you do not have that much money.\n");
printf("Your current balance is just:\t%.2f\n", balance);
printf("\n How much do you want to withdraw?\t");
scanf("%f",&withdraw);
new_balance-=withdraw;
current_bal=new_balance;
}
balance=current_bal;
printf("Your current balance is:\t $%.2f\n\n", balance);
if ( balance < min_bal ) {
min_bal = balance;
}
count_debit++; //counts debit transactions
day=newday;
}//end of option two
else if (option==3){ //if option 3 was selected
printf("Please enter a valid date from %d to %d\t", day, days_in_month);
scanf("%d", &newday);
while(newday > days_in_month || newday <day){
printf("Please enter a valid date from %d to %d\t", day, days_in_month);
scanf("%d", &newday);
}
printf("\n Current balance:\t $%.2f\n\n", balance);
printf("Minimum balance: \t $%.2f\n\n", min_bal);
day=newday;
}//end of option three
}//end of while statement
//option 4
interest=min_bal*(ANNUM/12); //computation of the interest
final=interest+balance;
printf("\nStatement of Account:\n\n");
printf("Credit Transactions: %d\n", count_credit);
printf("Debit Transactions: %d\n", count_debit);
printf("Current Balance:\t $%.2f \n", balance);
printf("Minimum Balance:\t $%.2f \n", min_bal);
printf("Interest Computed:\t $%.2f \n", interest);
printf("Final Balance:\t\t $%.2f \n", final);
printf("\nGood Bye! \n");
system ("pause");
return 0;
}