c语言猜价格.类似幸运52那样的

我自己写了一个,可是很多错误.希望能根据我的改下,使它能运行.谢谢!
#include<stdio.h>
#include<string.h>
int guess(float a,float b)
{int c;
if(a==b) c=1;
else(a>b) c=2;
if(a<b) c=3;
}
struct goods
{
char name[80];
int price;
}goods[2]{{"computer",7000},{"mobile phone",3000}};
main()
{int guess(float a,float b);
float x,y;
int z,choice;
for(;;)
{
clrscr();
printf("************************************\n");
printf("* main menu *\n");
printf("* 1. computer *\n");
printf("* 2.mobile phone *\n");
printf("* 3. exit *\n");
printf("************************************\n");
while(choice>1||choice<3);
if(choice==3) exit();
if(choice==1)
{x=goods[0].price;
printf("Input the price:\n");
scanf("%f",&y);
z=guess(x,y);
while(z!=1)
{if(z==1)
{printf("congratulation,you are right!\n");break;}
if(z==2)
{printf("too high!input again!\n");}
if(z==3)
{printf("too low!input again!"\n");}
}
}
if(choice==2)
{x=goods[1].price;
printf("Input the price:\n");
scanf("%f",&y);
z=guess(x,y);
while(z!=1)
{if(z==1)
{printf("congratulation,you are right!\n");break;}
if(z==2)
{{printf("too high!input again!\n");}
if(z==3)
{printf("too low!input again!"\n");}
}
}
getch();
}
}

第1个回答  2007-09-18
第一,你的guess()函数没返回值
第二,你调用clrscr();函数没加头文件"conio.h"
第三,你用的循环条件while(choice>1||choice<3);我觉得应该用&&
目前只找到这些了
第2个回答  2007-09-20
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<graphics.h>

int guess(float a,float b);

main()
{
float x,y;
int z,choice;
float goods[2]={7000,3000};
for(;;)
{
clrscr();
printf("************************************\n");
printf("* main menu *\n");
printf("* 1. computer *\n");
printf("* 2.mobile phone *\n");
printf("* 3. exit *\n");
printf("************************************\n");
printf("Enter you choice:");
scanf("%d",&choice);
if(choice==3) return(0);
if(choice==1)
{
x=goods[0];
printf("Input the price:\n");
scanf("%f",&y);
z=guess(x,y);
if(z ==1)
printf("congratulation,you are right!\n");
else if(z==2)
printf("too high!input again!\n");
else if(z==3)
printf("too low!input again!\n");
}
if(choice==2)
{
x=goods[1];
printf("Input the price:\n");
scanf("%f",&y);
z=guess(x,y);
if(z ==1)
printf("congratulation,you are right!\n");
else if(z==2)
printf("too high!input again!\n");
else if(z==3)
printf("too low!input again!\n");
}
getch();
}
}

int guess(float a,float b)
{
int c;
if(a==b) c=1;
else if(a>b) c=2;
else if(a<b) c=3;
return c;
}本回答被提问者采纳
相似回答