Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int menu(void);
- /* #1 */ void new_accounts(int *, float *, int *, float *);
- /* #2 */ void summary(int, float, int, float);
- /* #3 */ void withdraw(int, float *, float);
- /* #4 */ void deposit(int, float *, float);
- /* #5 */ void transfer(int, float *, int, float *, float);
- /* #6 */ void exchange(int, float *, int, float *);
- /* #7 */ int *high_balance(int *, float, int *, float, float *);
- /* #8 */ void reset(float *, float *);
- /* #9 */ void change(int *, int);
- int main(void){
- menu();
- return 0;
- }
- int menu (void){
- int choice;
- //menu Declarations
- int accountNum1;
- int accountNum2;
- float balance1;
- float balance2;
- //newAccounts Declarations
- int tmp=0;
- //withdraw Declaraions
- while(1==1){
- printf("\n--------------------------------\nMain Menu\n");
- printf("\n1 New Accounts\n2 All Accounts\n3 Withdraw\n4 Deposit\n5 Transfer Fund\n6 Exchange Balance\n7 High Balance");
- printf("\n8 Reset All Balance\n9 Change Account Number\n0 Exit\n");
- //menu format
- scanf("%d", &choice);
- switch(choice){
- case 1: new_accounts(&accountNum1, &balance1, &accountNum2, &balance2);
- break;
- case 2: summary(accountNum1, balance1, accountNum2, balance2);
- break;
- case 3:
- while((tmp!=accountNum1)&&(tmp!=accountNum2)){
- printf("Enter an account to withdraw (%d or %d?): ", accountNum1,accountNum2);
- scanf("%d", &tmp);
- if((tmp!=accountNum1)&&(tmp!=accountNum2))
- printf("invalid account number.\n");
- }
- printf("Enter an amount to withdraw: ");
- scanf("%d", &tmp);
- //input validation
- if (tmp== accountNum1){
- withdraw(accountNum1, &balance1, tmp);
- }
- else{
- withdraw(accountNum2, &balance2, tmp);
- }
- break;
- case 4:
- while((tmp!=accountNum1)||(tmp!=accountNum2)){
- printf("Enter an account to deposit (%d or %d?): ", accountNum1,accountNum2);
- scanf("%d", &tmp);
- printf("Enter an amount to deposit: ");
- scanf("%d", &tmp);
- if((tmp!=accountNum1)&&(tmp!=accountNum2))
- printf("invalid account number.\n");
- }
- //input validation
- if (tmp== accountNum1){
- withdraw(accountNum1, &balance1, tmp);
- }
- else{
- withdraw(accountNum2, &balance2, tmp);
- }
- break;
- /*
- case 5: transfer();
- break;
- case 6: exchange();
- break;
- case 7: *high_balance();
- break;
- case 8: reset();
- break;
- case 9: change();
- break;
- */
- case 0: exit(0);
- printf("Goodbye!");
- break;
- default: printf("invalid input");
- break;
- }
- }
- }
- void new_accounts(int* accountNum1, float*balance1, int*accountNum2, float*balance2){
- int flag=0;
- while(flag==0){
- srand(time(0));
- *accountNum1= rand()%59+54;
- *balance1= rand()%999+(-100);
- *accountNum2= rand()%59+54;
- *balance2= rand()%999+(-100);
- if(accountNum1== accountNum2){
- flag=0;
- }
- else{
- flag=1;
- }
- }
- printf(">>>>Accounts created.");
- }
- void summary(int accountNum1, float balance1, int accountNum2, float balance2){
- printf("\n>>>>%5d: $%-10.2f", accountNum1, balance1);
- printf("\n>>>>%5d: $%-10.2f", accountNum2, balance2);
- }
- void withdraw(int accountNum, float * newBalance, float withdrawl ){
- printf(">>>> Account %d has changed from %.2f to %.2f", accountNum, *newBalance, *newBalance-withdrawl);
- *newBalance-= withdrawl;
- }
- void deposit(int accountNum, float * newBalance, float withdrawl ){
- printf(">>>> Account %d has changed from %f to %f", accountNum, *newBalance, *newBalance-withdrawl);
- *newBalance-= withdrawl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement