帮我写一下c语言大作业吧,非常紧急,是关于猜价格游戏的。
angel
2024-12-01 18:29:14
最佳回答
include
include
include
void introduction(){
printf("猜价格游戏,。\n");}
int startgame(){
int price,player;int i;time_t t;srand((unsigned)time(&t));price=rand()%101+100;printf("%d\n",price);for(i=0;i;i+){
printf("请输入价格:");scanf("%d",&player);if(player>price)
printf("高\n");else if(player)
printf("低\n");else{
printf("恭喜你!猜对了!\n");return i;break;}
}
printf("很遗憾!没有猜对!\n");return-1;}
double winingper(int winnum,int total){
double per,prinper;if(total=0){
printf("你还没有进行游戏!\n");return-1;}
per=(double)winnum/total;prinper=per*100;printf("你的胜率为:%.1lf%\n",prinper);return prinper;}
int **erage(int score,int num){
if(num=0){
printf("你还没有进行游戏!\n");return-1;}
printf("你的平均分为:%d\n",score/num);return score/num;}
int gameover(){
exit(1);}
void menu(){
printf("*menu*\n");printf("1.游戏介绍\n");printf("2.开始游戏\n");printf("3.输出胜率\n");printf("4.输出平均成绩\n");printf("5.\n");printf("6.退出游戏\n");printf("*\n");}
void main(){
int i,select,flag;int count=0,wincount=0,score=0;label:
menu();scanf("%d",&select);switch(select){
case 1:introduction();goto label;break;case 2:flag=startgame();count+;if(flag!1){
wincount+;score+(5-flag)*2;}
goto label;break;case 3:winingper(wincount,count);goto label;break;case 4:**erage(score,count);goto label;break;case 5:goto label;break;case 6:exit(1);break;default:
printf("错误的选择项!\n");break;}
} 20210311