I'm new to this boards, and I need some help finishing a project for school.
Im using nested if-statements inside a while loop to execute different actions. action C consist of printing the number of times a person executed action A and action B. For that a declared variables intCounterB and intCounterC, and included the intCounterB=++intCounterB to achieve my desired results, but I ended up getting some funny numbers.
The code I use is the following.
____________________________________
Expand|Select|Wrap|Line Numbers
- #include <stdio.h>
- int main (void) {
- int intOption;
- float floatTotal=2000;
- printf("\n");
- printf("Ficticious Bank of American\n");
- printf("\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 on last day and exit the program\n");
- while (intOption<4) {
- int intCounterCredit, intCounterDebit;
- printf("\n");
- printf(" Please select an option: ");
- scanf("%d", &intOption);
- printf(" you selected option %d\n", intOption);
- if (intOption == 1){
- float floatCredit;
- int intDate, intCounterCredit;
- intCounterCredit=++intCounterCredit;
- printf("\n");
- printf(" Please enter today's date: ");
- scanf("%d", &intDate);
- printf(" Amount to be credited: ");
- scanf("%f", &floatCredit);
- floatTotal=floatTotal+floatCredit;
- printf(" Your new account blances is $%.2f\n", floatTotal);
- }
- else
- {
- if (intOption == 2){
- float floatDebit;
- int intDate;
- intCounterDebit=++intCounterDebit;
- printf("\n");
- printf(" Please enter today's date: ");
- scanf("%d", &intDate);
- printf(" Amount to be dedited: ");
- scanf("%f", &floatDebit);
- floatTotal=floatTotal-floatDebit;
- printf(" Your new account blances is $%.2f\n", floatTotal);
- }
- else
- {
- if (intOption == 3){
- int intDate;
- printf("\n");
- printf(" Please enter today's date: ");
- scanf("%d", &intDate);
- printf(" Your new account blances is $%.2f\n", floatTotal);
- printf(" Total number of credit transactions: %d\n", intCounterCredit);
- printf(" Total number of debit transactions: %d\n", intCounterDebit);
- }
- else
- {
- printf("FU");
- }
- }
- }
- }
- return 0;
- }
The results were as follow after running it.
Ficticious Bank of American
1) Deposit funds (credit transaction)
2) Withdraw funds (debit transaction)
3) Print statement of account
4) Compute interest on last day and exit the program
Please select an option: 1
you selected option 1
Please enter today's date: 15
Amount to be credited: 200
Your new account blances is $2200.00
Please select an option: 1
you selected option 1
Please enter today's date: 19
Amount to be credited: 200
Your new account blances is $2400.00
Please select an option: 2
you selected option 2
Please enter today's date: 19
Amount to be dedited: 650
Your new account blances is $1750.00
Please select an option: 3
you selected option 3
Please enter today's date: 19
Your new account blances is $1750.00
Total number of credit transactions: -16843009
Total number of debit transactions: 43197
Please select an option:
___________________________________________
The problem is with the number of transactions printed.
Its supposed to be 1 and 2.
Any help is deeply appreciated, since I have to turn this project tomorrow morning.