源程序有错误 请大家帮忙找找

来源:百度知道 编辑:UC知道 时间:2024/05/04 21:41:53
#include "stdio.h"
#include "stdlib.h"
#include "time.h"

void guess();

main ()
{
printf("You have 10$.\n");
guess();
}

void guess()
{
int num=0,temp=0;
int m=10;
char c;
do
{
srand(time(NULL));
num=rand();
num=num%2+1;
printf("please press B or S:");
c=getche();
c=='b'?temp=1:(c=='s'?temp=2:exit(1));
if((temp==num)&&(temp==1)) m+=8;
if((temp==num)&&(temp==2)) m+=4;
if(temp!=num) m-=5;
printf("You have %d$\n",m);
}while((temp==1)||(temp==2));
}
调试时候出现--------------------Configuration: lf - Win32 Debug--------------------
Compiling...
11.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\lf\11.cpp(11) : warning C4508: 'main' : function should return a value; 'void' retu

getche改成getchr

1.C2065: 'getche' : undeclared identifier
c=getche(); 应该是c=getchar();

2.C:\Program Files\Microsoft Visual Studio\MyProjects\lf\11.cpp(11) : warning

这个是警告信息可以不管它
3.void guess()
{
int num=0,temp=0;
int m=10;
char c;
do
{
srand(time(NULL));
这个不用加void 因为这个要有返回值,而void 的意思是没有返回值的,
你修改一下看看,我这里没有装dos,没有办法调试,我只是看着说的~~如果不对,那就不好意思了~~

#include "stdio.h"
#include "stdlib.h"
#include "time.h"
#include "conio.h" //getch()函数支持

void guess();

main ()
{
printf("You have 10$.\n");
guess();
return 0;//需要返回值
}

void guess()
{
int num=0,temp=0;
int m=10;
char c;
do
{
srand(time(NULL));
num=rand();
num=num%2+1;
printf("please press B or S:");
c=getch(); <