首页 > 代码库 > 公交一卡通2
公交一卡通2
#include <stdio.h>
#include <unistd.h>
#include<windows.h>
void stop(void)
{
system("pause");
}
int main()
{
int stops=0,money=0; //先定义变量
char chose,choose;
system("cls");
printf("\n\t\t||------------------------------||");
printf("\n\t\t||------------------------------||"); //第一界面
printf("\n\t\t||-------------Welcome----------||");
printf("\n\t\t||----------use bus traffic-----||");
printf("\n\t\t||--------------card------------||");
printf("\n\t\t||------------------------------||");
printf("\n\t\t||------------------------------||");
printf("\n\n\n\n"); ///查找一下怎么清屏再写
Sleep(4000);
system("cls");
printf("\n\t\t||------------------------------||");
printf("\n\t\t||------------------------------||");
printf("\n\t\t| 1.Add new card |");
printf("\n\t\t| 2.Logout card |");
printf("\n\t\t| 3.Modify card |"); //第二界面
printf("\n\t\t| 4.Read card |");
printf("\n\t\t| 5.Save money |");
printf("\n\t\t| 6.Stat.max money |");
printf("\n\t\t| 7.Display |");
printf("\n\t\t| 8.Delete |");
printf("\n\t\t| 0.Exit |");
printf("\n\t\t||------------------------------||");
printf("\n\t\t||------------------------------||");
printf("\n\n\n");
printf("please give your change:");
scanf("%c",&chose); //chose 是自定义的 scanf 函数获取输入字符 !!!注意是字符型不是数字
switch(chose)
{
case ‘1‘:printf("\n\t\t Your chose is 1"); break;
case ‘2‘:printf("\n\t\t Your chose is 2"); break;
case ‘3‘:printf("\n\t\t Your chose is 3"); break;
case ‘4‘:printf("\n\t\t Your chose is 4"); ///输入界面
printf("\n\t\t please input your stops:");
scanf ("%d",&stops);
if (stops<1||stops>30)
{
printf("\n\t\t input error please try again");
getch(); //重新回到上一界面
}
else if (stops<=10) ///用else if
{
printf("\n\t\t Your ticket is 1");break; //记得break
}
else if (10<stops<=15)
{ //无法返回上一级 ?????
printf("\n\t\t Your ticket is 2");break;
}
else if (15<stops<=20)
{
printf("\n\t\t Your ticket is 3");break;
}
else if (20<stops<=25)
{
printf("\n\t\t Your ticket is 4");break;
}
else if (25<stops<=30)
{
printf("\n\t\t Your ticket is 5");break;
}
case ‘5‘:printf("\n\t\t How much is your save:");
scanf ("%d",&money);
if (money <=0)
{
printf ("\n\t\t error !!!! please check it");
}
getch();
break;
case ‘6‘:printf("\n\t\t Your chose is 6"); break;
case ‘7‘:printf("\n\t\t Your chose is 7"); break;
case ‘8‘:printf("\n\t\t Your chose is 8"); break;
case ‘0‘:printf("\n\t\t Are you sure exit?(y/n)");
scanf("%c",&choose);
if (choose==‘y‘||choose==‘Y‘) ///字符型的加引号
{
exit(0);
}
default:("\n\t\t input error");
}
getch(); //why
stop();
return(0);
}
公交一卡通2