gpt4 book ai didi

c - 需要帮助完成我的 ATM 机

转载 作者:行者123 更新时间:2023-11-30 15:14:09 25 4
gpt4 key购买 nike

它用于我的 C 编程类(class),它是一个简单的 ATM,可以执行 4 个操作:提款,存款,帐户详细信息,检查用户余额,然后退出。我已经做了简单的基础,但由于项目要求的变化,我现在需要在其中放置密码因素,我已经尝试过并提出了使用以下代码,但我想让它在主菜单之前要求输入密码,即:存款、取款等...我也尝试过使用 switch case 但我觉得这没有改变任何东西。任何帮助都是非常感谢。

到目前为止我完成的代码是:

 #include<stdio.h>
#include<conio.h>
int atmfun();
main()
{
int option1;
do
option1=atmfun();
while (option1==1);

getch();
}

int atmfun()
{


char Name1[]="Fever";
char Name2[]="JACK";
char Name3[]="JOHN";
char choice='y',choice1='n';
char FullName1[]="Fever tyrell";
char FullName2[]="Jack williams";
char FullName3[]="John Mason";
int i,a,AccBalance = 20000;
int acc_type,password,option,option1;
int passworda=31081;
int passwordb=12345;
int passwordc=12456;
int w_amount,d_amount;
printf("Welcome to generic ATM\n");
printf("\n\nPlease choose an option...");
printf("\n(1)View account details.");
printf("\n(2)Check balance.");
printf("\n(3)Withdraw amount.");
printf("\n(4)Deposit amount.");
printf("\n(5)Exit.\n");
scanf("\n%d",&option);



//start of option 1
if(option==1) //if user wants to view their account details
{
printf("PLEASE ENTER YOUR PASSWORD: ");
scanf("%d",&password);

if
(password!=passworda&&password!=passwordb&&password!=passwordc)

printf("YOU HAVE ENTERED AN INVALID PASSWORD");
else
if(password==passworda)
{
printf("WELCOME Mr.%s\n\n",Name1);
//rest of the account details
}
else
if(password==passwordb)
{
printf("WELCOME Mr.%s\n\n",Name2);
//rest of the acc details
}
else
if(password==passwordc)
{
printf("WELCOME Mr.%s\n\n",Name3);
//rest of the acc details
}
{
printf("\nDo you wish to go back to the main menu?\nEnter 1 for YES, and any other number for NO\n");
scanf("%d",&option1);
if (option1==1)
{
return option1;
}
else
printf("Thank you for using Generic ATM");
return 0;
}
}
// end of option1

// start of option 2
if(option==2) // if user wants to view his account balance
{
printf("Your account balance is $%d",AccBalance);

printf("\nDo you wish to go back to the main menu? \nEnter 1 for YES, and any other number for NO\n");
scanf("%d",&option1);
if (option1==1)
{
return option1;
}
else
printf("Thank you for using Generic ATM");
return 0;
}

//end of option 2


//start of option 3
if(option==3)// if user wants to withdraw money
{
printf("Enter amount to withdraw\n$");
scanf("%d",&w_amount);
{
if(w_amount<=0)
{
printf("Amount cannot be a number under zero or zero");
for(i=4;i>0;i--)
{
printf("\nEnter appropriate amount,you have %d tries left\n",i);
{
printf("Enter amount to withdraw\n$");
scanf("%d",&w_amount);
if(w_amount<=0)
{
printf("You cannot withdraw this amount");
}
}
if (i==1)
printf("\nYou have exceeded your tries\n");
}
}
else
if(w_amount>AccBalance)
{
printf("You don't have sufficient funds, please enter the amount within your Account Balance");
for(i=4;i>0;i--)
{
printf("\nEnter appropriate amount,you have %d tries left\n",i);
{
printf("Enter amount to withdraw\n$");
scanf("%d",&w_amount);
if(w_amount<=0)
{
printf("You cannot withdraw this amount");
}
}
if (i==1)

printf("\nYou have exceeded your tries\n");

}
}
else
{
AccBalance=AccBalance-w_amount;
printf("Your new balance is $%d",AccBalance);
}
}
printf("\nDo you wish to go back to the main menu?\nEnter 1for YES, and any other number for NO\n");

scanf("%d",&option1);
if (option1==1)
{
return option1;
}
else
printf("Thank you for using Generic ATM");
return 0;
}
//end of option 3

//start of option 4
if (option==4) // if user wants to deposit dem moneys bbby
{
printf("Enter amount to deposit\n$");
scanf("%d",&d_amount);
if(d_amount<=0)
{
printf("You cannot deposit this amount");
for(i=4;i>0;i--)
{
printf("\nEnter appropriate amount,you have %d tries left\n",i);
{
printf("Enter amount to deposit\n$");
scanf("%d",&d_amount);
if(d_amount<=0)
{
printf("You cannot deposit this amount");
}
}
if (i==1)
printf("\nYou have exceeded your tries\n");
}
}
else
{
AccBalance=AccBalance+d_amount;
printf("You have deposited $%d",d_amount);
printf("\nYour New balance is $%d",AccBalance);
}
printf("\nDo you wish to go back to the main menu?\nEnter 1 for YES, and any other number for NO\n");
scanf("%d",&option1);
if (option1==1)
{
return option1;
}
else
printf("Thank you for using Generic ATM");
return 0;
}
//end of option 4

//start of option 5
{
if (option == 5);
printf("\nThank you for using Generic ATM\n");
return option;
}
//end of option 5
return 0;

getch();
}

最佳答案

int main(){
while true{
if (checkPassword()) handleTransaction();
};
};

看看如果你不做 main 中的所有事情是多么容易吗?

关于c - 需要帮助完成我的 ATM 机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34157292/

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