#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//个人信息
typedef struct Person {
char name[20];
char account[20];
char password[8];
float money;
} Person;
typedef struct Node {
Person p;
struct Node *next;
} Node, *NodeList;
NodeList head = NULL;
//开函数
void Create_account() {
NodeList pNewNode = (NodeList)malloc(sizeof(Node));
pNewNode->next = NULL;
pNewNode->p.money = 0.0;
printf("请输入你的姓名,账号和密码\n");
scanf("%s", pNewNode->p.name);
scanf("%s", pNewNode->p.account);
scanf("%s", pNewNode->p.password);
if (head == NULL)
head = pNewNode;
else {
NodeList p = head;
while (p->next != NULL)
p = p->next;
p->next = pNewNode;
}
printf("你的账号信息如下\n");
printf("\t姓名:%s\n", pNewNode->p.name);
printf("\t账号:%s\n", pNewNode->p.account);
printf("\t钱款:%f\n", pNewNode->p.money);
printf("恭喜你开成功!!!\n");
printf("---------------------------------\n");
printf("|\t 1.开\t|\t 2.登录\t|\n");
printf("|\t 3.退出\t|\n");
printf("---------------------------------\n");
getchar();
}
//登录函数
int Login(char *account, char *password) {
NodeList p = head;
while (p != NULL) {
if (strcmp(p->p.account, account) == 0 && strcmp(p->p.password, password) == 0)
return 1;
p = p->next;
}
return 0;
}
//存款函数
void Cun_money(char *account, float money) {
NodeList p = head;
while (p != NULL) {
if (strcmp(p->p.account, account) == 0) {
p->p.money += money;
printf("存款成功,当前余额为%.2f\n", p->p.money);
return;
}
p = p->next;
}
}
//取款函数
void Qu_money(char *account, float money) {
NodeList p = head;
while (p != NULL) {
if (strcmp(p->p.account, account) == 0) {
if (p->p.money < money)
printf("余额不足,取款失败\n");
else {
p->p.money -= money;
printf("取款成功,当前余额为%.2f\n", p->p.money);
}
return;
}
p = p->next;
}
}
//显示账户信息函数
void Display(char *account) {
NodeList p = head;
while (p != NULL) {
if (strcmp(p->p.account, account) == 0) {
printf("姓名:%s\n", p->p.name);
printf("账号:%s\n", p->p.account);
printf("余额:%.2f\n", p->p.money);
return;
}
p = p->next;
}
}
int main() {
printf("****************************************\n");
printf("**********欢迎使用ATM存取系统***********\n");
printf("****************************************\n");
printf("---------------------------------\n");
printf("|\t 1.户\t|\t 2.登录\t|\n");
printf("|\t 3.退出\t|\n");
printf("---------------------------------\n");
while (1) {
char ch = getchar();
getchar();
switch (ch) {
case '1':
Create_account();
break;
case '2': {
char Account[20], Password[8];
printf("请输入账号和密码\n");
scanf("%s", Account);
scanf("%s", Password);
getchar();
if (Login(Account, Password)) {
printf("登录成功\n");
printf("-------------------------------------------------\n");
printf("| 1.存款\t| 2.取款\t| 3.查询\t| 4.退出 |\n");
printf("-------------------------------------------------\n");
while (1) {
char op = getchar();
if (op == '1') {
float money;
printf("请输入存款金额\n");
scanf("%f", &money);
Cun_money(Account, money);
printf("-------------------------------------------------\n");
printf("| 1.存款\t| 2.取款\t| 3.查询\t| 4.退出 |\n");
printf("-------------------------------------------------\n");
continue;
} else if (op == '2') {
float money;
printf("请输入取款金额\n");
scanf("%f", &money);
Qu_money(Account, money);
printf("-------------------------------------------------\n");
printf("| 1.存款\t| 2.取款\t| 3.查询\t| 4.退出 |\n");
printf("-------------------------------------------------\n");
continue;
} else if (op == '3') {
Display(Account);
printf("-------------------------------------------------\n");
printf("| 1.存款\t| 2.取款\t| 3.查询\t| 4.退出 |\n");
printf("-------------------------------------------------\n");
continue;
}
else if (op == '4') {
system("CLS");
printf("****************************************\n");
printf("**********欢迎使用ATM存取系统***********\n");
printf("****************************************\n");
getchar();
break;
}
}
} else
printf("账号或密码错误\n");
printf("---------------------------------\n");
printf("|\t 1.户\t|\t 2.登录\t|\n");
printf("|\t 3.退出\t|\n");
printf("---------------------------------\n");
}
break;
case '3':
printf("谢谢使用!\n");
exit(0);
break;
}
}
}
标签:account,NodeList,pNewNode,money,ATM,char,printf
From: https://blog.51cto.com/u_16030624/7334983