gpt4 book ai didi

c - 在另一个函数中使用指针 - 银行程序

转载 作者:行者123 更新时间:2023-11-30 20:36:22 26 4
gpt4 key购买 nike

我对我正在编写的这段代码有一个简单的问题。引用void RunBankMenu(int *choice)void TransactionDecision(...),我将如何使用从RunBankMenu(Choice)获取的值> 为 TransactionDecision 设置 if/else 或 switch 语句?例如,如果用户选择 1,TransactionDecision 函数将使用我也设置开关的那批代码。如何将指针传递给另一个函数以便读取该值?

谢谢!

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define MAXCREDIT -4500

void RunBankMenu(int *choice);
void Greeting();
void AccountBalance(double account, char letter);
void TransactionDecision(int num, double *cPtr, double *sPtr, double *xPtr);
void DepositMoney(double *accountPtr);
void WithdrawMoney(double *accountPtr, char letter);

int main()
{
double checkings = 430.00;
double savings = 812.00;
double credit = -2254.00;

int NumberChoice = 0;
Greeting();
AccountBalance(checkings, savings, credit);
RunBankMenu(&NumberChoice);

printf("%d", NumberChoice);
}


void Greeting()
{
printf("Welcome to the Bank of COP 2220\n\nIt is a pleasure to manage"
" your checking, savings, and credit accounts\n");
}

void AccountBalance(double account, char letter)
{
double checkings = 430.00;
double savings = 812.00;
double credit = -2254.00;

printf("-- You currently have $%.2f in your checking account\n",checkings);
printf("-- You currently have $%.2f in your savings account\n",savings);
printf("-- You currently have $%.2f credit balance\n", credit);
}



void RunBankMenu(int *choice)
{
do{
printf("-----------------------------\n");
printf("(1) to DEPOSIT to CHECKING\n");

printf("(2) to WITHDRAW from CHECKING\n");

printf("(3) to DEPOSIT to SAVINGS\n");

printf("(4) to WITHDRAW from SAVINGS\n");

printf("(5) to DEPOSIT to CREDIT\n");

printf("(6) to TAKE an ADVANCE from CREDIT\n");

printf("(7) to TRANSFER MONEY BETWEEN ACCOUNTS\n");

printf("(8) for all ACCOUNT BALANCES\n");

printf("\n(9) QUIT\n\n");

printf("Select an option: ");
scanf("%d", &*choice);
} while (*choice <= 8);


}

void TransactionDecision(int num, double *cPtr, double *sPtr, double *xPtr)
{
int num1;
}

void DepositMoney(double *accountPtr)
{

}

void WithdrawMoney(double *accountPtr, char letter)
{

}

最佳答案

也许这段代码可以帮助您入门......

#include <stdio.h>

typedef struct accounts_S
{
double checkings;
double savings;
double credit;
} accounts_T;

void DepositMoney(double *accountPtr)
{

}

void WithdrawMoney(double *accountPtr)
{

}

void TransferBetweenAccounts(accounts_T *accounts)
{

}

void AccountBalance(
accounts_T *I__accounts
)
{
printf("-- You currently have $%.2f in your checking account\n", I__accounts->checkings);
printf("-- You currently have $%.2f in your savings account\n", I__accounts->savings);
printf("-- You currently have $%.2f credit balance\n", I__accounts->credit);

return;
}

void TransactionDecision(int NumberChoice, accounts_T *accounts)
{
switch(NumberChoice)
{
case 1:
DepositMoney(&accounts->checkings);
break;

case 2:
WithdrawMoney(&accounts->checkings);
break;

case 3:
DepositMoney(&accounts->savings);
break;

case 4:
WithdrawMoney(&accounts->savings);
break;

case 5:
DepositMoney(&accounts->credit);
break;

case 6:
WithdrawMoney(&accounts->credit);
break;

case 7:
TransferBetweenAccounts(accounts);
break;

case 8:
AccountBalance(accounts);
break;
}

return;
}

void Greeting()
{
printf("Welcome to the Bank of COP 2220\n"
"\n"
"It is a pleasure to manage your checking, savings, and credit accounts\n"
);

return;
}

void RunBankMenu(
int *choice
)
{
printf("-----------------------------\n");
printf("(1) to DEPOSIT to CHECKING\n");
printf("(2) to WITHDRAW from CHECKING\n");
printf("(3) to DEPOSIT to SAVINGS\n");
printf("(4) to WITHDRAW from SAVINGS\n");
printf("(5) to DEPOSIT to CREDIT\n");
printf("(6) to TAKE an ADVANCE from CREDIT\n");
printf("(7) to TRANSFER MONEY BETWEEN ACCOUNTS\n");
printf("(8) for all ACCOUNT BALANCES\n");
printf("\n(9) QUIT\n\n");

do {
printf("Select an option: ");
scanf("%d", choice);
} while((0 == *choice) && (*choice > 9));

return;
}

int main()
{
int rCode = 0;
int NumberChoice;
accounts_T accounts =
{
.checkings = 430.00,
.savings = 812.00,
.credit = -2254.00
};

Greeting();
AccountBalance(&accounts);

do {
RunBankMenu(&NumberChoice);
TransactionDecision(NumberChoice, &accounts);
} while(9 != NumberChoice);

return(rCode);
}

关于c - 在另一个函数中使用指针 - 银行程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36269762/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com