Code:
/* Adam Jones
COP3223 Sec 0001
Lab 3, part 2
10/13/07
*/
#include <stdio.h>
int main(void) {
//Declare all variables
float CREDIT, DEPOSIT, NEW_BALANCE, NEW_CREDIT, WITHDRAWL, MIN_BALANCE, INTEREST, FINAL_BALANCE;
int INPUT, CREDIT_TRANS = 0, DEBIT_TRANS = 0, MONTH, NUMBER_OF_DAYS, DATE1, DATE2;
//Set starting balance
CREDIT = 2000.00;
//Request user to enter a transaction month
printf("Enter the transaction month:\n");
scanf("%i", &MONTH);
//Define number of days in month entered
if (MONTH == 1) {
NUMBER_OF_DAYS = 31;
}
else if (MONTH == 2) {
NUMBER_OF_DAYS = 28;
}
else if (MONTH == 3) {
NUMBER_OF_DAYS = 31;
}
else if (MONTH == 4) {
NUMBER_OF_DAYS = 30;
}
else if (MONTH == 5) {
NUMBER_OF_DAYS = 31;
}
else if (MONTH == 6) {
NUMBER_OF_DAYS = 30;
}
else if (MONTH == 7) {
NUMBER_OF_DAYS = 31;
}
else if (MONTH == 8) {
NUMBER_OF_DAYS = 31;
}
else if (MONTH == 9) {
NUMBER_OF_DAYS = 30;
}
else if (MONTH == 10) {
NUMBER_OF_DAYS = 31;
}
else if (MONTH == 11) {
NUMBER_OF_DAYS = 30;
}
else if (MONTH == 12) {
NUMBER_OF_DAYS = 31;
}
//Display number of days for month and current balance
printf("Number of days in this month: %i\n", NUMBER_OF_DAYS);
printf("Your current balance is $%2.2f.\n", CREDIT);
DATE1 = 1;
while ( INPUT != 4 ) {
//list transaction options; request user to choose one
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: \n");
scanf("%i", &INPUT);
//request day of month to be entered
if (INPUT != 4) {
printf("Please enter a valid date from %i to %i:\n", DATE1, NUMBER_OF_DAYS);
scanf("%i\n", &DATE2);
}
//take care of invalid dates
if (DATE2 < DATE1){
printf("Please enter a valid date from %i to %i:\n", DATE1, NUMBER_OF_DAYS);
scanf("%i\n", &DATE2);
//Can't figure out the bug here; Program does not execute to next function, but if user
//enters another number the following function executes. worked on this for three days....
if(DATE2 >= DATE1){
DATE1 = DATE2;
}
}
//deposit function
if ( INPUT == 1 ) {
printf("How much do you want to deposit?\n");
scanf("%f", &DEPOSIT);
CREDIT = CREDIT + DEPOSIT;
printf("Your current balance is $%1.2f.\n", CREDIT);
CREDIT_TRANS++;
}
//debit function
if ( INPUT == 2 ) {
printf("How much do you want to withdrawl?\n");
scanf("%f", &WITHDRAWL);
CREDIT = CREDIT - WITHDRAWL;
printf("Your current balance is $%1.2f.\n", CREDIT);
DEBIT_TRANS++;
MIN_BALANCE = 2000.00;
//minimum balance calculator
if ( MIN_BALANCE > CREDIT ) {
MIN_BALANCE = CREDIT;
}
}
//balance function
if ( INPUT == 3 ) {
printf("Current balance: $%1.2f.\n", CREDIT);
printf("Minimum balance: $%1.2f.\n", MIN_BALANCE);
}
}
//statement function
if (INPUT == 4){
INTEREST = (MIN_BALANCE*0.035)/12.00;
FINAL_BALANCE = CREDIT + INTEREST;
printf("Statement of Account:\n");
printf("Credit transactions: %i,\n", CREDIT_TRANS);
printf("Debit transactions: %i,\n", DEBIT_TRANS);
printf("Current balance: $%1.2f,\n", CREDIT);
printf("Minimum balance: $%1.2f,\n", MIN_BALANCE);
printf("Interest computed: $%1.2f,\n", INTEREST);
printf("Final balance: $%1.2f,\n", FINAL_BALANCE);
printf("Good Bye!\n");
}
system ("PAUSE");
return 0;
}
in the section where I request the user to "enter a valid date from x to x", after the date is entered, the program simply goes to a new line. Then if you enter any number, it automatically proceeds to carry out the transaction function requested (example: if you type 200 and then enter, it will print ask to enter the deposit amount, but the deposit is already made" Im almost there, what am I missing?