1、源程序
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void buy();
void quit();
void save();
void jilu();
struct piao
{
char name[20];
}lg[5]={"昆明","长沙","武汉","郑州","北京"};
int a,b,c,d,q,w,e,r,t,n;
void main()
{ char choice[1];
while (choice[0]!='3')
{
printf("\n1. 购买车票\n");
printf("\n2. 售票记录\n");
printf("\n3. 退出\n");
printf("\n 请选择(1-3):");
scanf("%s",choice);
switch (choice[0])
{
case '1': buy();break ;
case '2': jilu();break;
case '3': quit();break ;
}
}
}
void buy()
{int f;
char reply;
int i,m;
int BuyTicket(int a,int b);
n=0;q=0;w=0;e=0;r=0;t=0;
printf("昆明--1\n长沙--2\n武汉--3\n郑州--4\n北京--5\n");
printf("\n输入起点站代号\n");
6
scanf("%d",&a);
printf("输入终点站代号 \n");
scanf("%d",&b);
printf("%10s-->%10s\n",lg[a-1].name,lg[b-1].name);
if(a!=b && a>0 && a<6 && b>0 && b<6)
{m=BuyTicket(a,b);n=n+m;}
else
{printf("错误");}
switch(b)
{
case 1:q++;break;
case 2:w++;break;
case 3:e++;break;
case 4:r++;break;
case 5:t++;break;
}
save();
printf("继续请按1,退出按任意键");
scanf("%d",&f);
if(f!=1) main();
}
int BuyTicket(int a,int b)
{int sum(int a,int b);
if(a<b)
return(sum(a,b));
if(a>b)
return(sum(b,a));
if(a==b)
return(sum(a,a));
}
int sum(int a,int b)
{int i;
c=0;d=0;
for(i=a;i<b;i++)
{if(i==1)
{c=c+68;d=d+700;}
if(i==2)
{c=c+90;d=d+1100;}
if(i==3)
{c=c+85;d=d+1000;}
if(i==4)
{c=c+60;d=d+500;}需要全部代码的请联系QQ752018766