写了一段代码但是有一些错误
Wrote a code but there are some errors
#include <stdio.h>
#include <stdlib.h>
int randomNumber(int);
void checkNumber(float,float);
int main()
{
int number ,guess = 0,check=0;
char choice='Y';
number = randomNumber();
printf("%d\n",number);
while(1)
{
switch(choice)
{
case 'Y':
printf("Guess the number that is between 1-20:\n");
scanf("%d",&guess);
checkNumber(number,guess);
break;
case 'N'
printf("BYE BYE....\n")
break;
default:
printf("Please enter a valid choice\n");
}
if(check==0 && choice == 0 'Y')
{
printf("***********\nDo you want to contiune to guess number?(Y/N)\n");
scanf("%c",&choice);
printf("***********\n");
}
else break;
}
return 0;
int randomNumber()
{
return (rand()%10)
}
}
void checkNumber()
if (n<g)
{
printf("Guess a lower value!\n\n");
return 0;
}
else if (n<g)
{
printf("Guess a higher value!\n\n");
return 0;
}
else
{
printf("****Cong.,You guessed the number ****\n\n");
return 1;
}
一个让用户猜测程序选择的幸运数字的程序。它使用一个 for 循环和大量 if 语句,但有一些逻辑或语法 errors.I 无法解决 problem.any 感谢帮助,在此先感谢。
语法非常糟糕,甚至无法编译。
我认为这应该有效:
#include <stdio.h>
#include <stdlib.h>
int randomNumber();
int checkNumber(int,int);
int main()
{
int number ,guess = 0,check=0;
char choice='Y';
number = randomNumber();
printf("%d\n",number);
while(1)
{
switch(choice)
{
case 'Y':
printf("Guess the number that is between 1-20:\n");
scanf("%d",&guess);
checkNumber(number,guess);
break;
case 'N':
printf("BYE BYE....\n")
break;
default:
printf("Please enter a valid choice\n");
}
if(check==0 && choice == 'Y')
{
printf("***********\nDo you want to continue to guess number?(Y/N)\n");
scanf("%c",&choice);
printf("***********\n");
}
else break;
}
return 0;
}
int randomNumber(){
return (rand()%10);
}
int checkNumber(int n, int g){
if (n<g)
{
printf("Guess a lower value!\n\n");
return 0;
}
else if (n>g)
{
printf("Guess a higher value\n\n");
return 0;
}
else
{
printf("****Cong.,You guessed the number ****\n\n");
return 1;
}
}
#include <stdio.h>
#include <stdlib.h>
int randomNumber(int);
void checkNumber(float,float);
int main()
{
int number ,guess = 0,check=0;
char choice='Y';
number = randomNumber();
printf("%d\n",number);
while(1)
{
switch(choice)
{
case 'Y':
printf("Guess the number that is between 1-20:\n");
scanf("%d",&guess);
checkNumber(number,guess);
break;
case 'N'
printf("BYE BYE....\n")
break;
default:
printf("Please enter a valid choice\n");
}
if(check==0 && choice == 0 'Y')
{
printf("***********\nDo you want to contiune to guess number?(Y/N)\n");
scanf("%c",&choice);
printf("***********\n");
}
else break;
}
return 0;
int randomNumber()
{
return (rand()%10)
}
}
void checkNumber()
if (n<g)
{
printf("Guess a lower value!\n\n");
return 0;
}
else if (n<g)
{
printf("Guess a higher value!\n\n");
return 0;
}
else
{
printf("****Cong.,You guessed the number ****\n\n");
return 1;
}
一个让用户猜测程序选择的幸运数字的程序。它使用一个 for 循环和大量 if 语句,但有一些逻辑或语法 errors.I 无法解决 problem.any 感谢帮助,在此先感谢。
语法非常糟糕,甚至无法编译。 我认为这应该有效:
#include <stdio.h>
#include <stdlib.h>
int randomNumber();
int checkNumber(int,int);
int main()
{
int number ,guess = 0,check=0;
char choice='Y';
number = randomNumber();
printf("%d\n",number);
while(1)
{
switch(choice)
{
case 'Y':
printf("Guess the number that is between 1-20:\n");
scanf("%d",&guess);
checkNumber(number,guess);
break;
case 'N':
printf("BYE BYE....\n")
break;
default:
printf("Please enter a valid choice\n");
}
if(check==0 && choice == 'Y')
{
printf("***********\nDo you want to continue to guess number?(Y/N)\n");
scanf("%c",&choice);
printf("***********\n");
}
else break;
}
return 0;
}
int randomNumber(){
return (rand()%10);
}
int checkNumber(int n, int g){
if (n<g)
{
printf("Guess a lower value!\n\n");
return 0;
}
else if (n>g)
{
printf("Guess a higher value\n\n");
return 0;
}
else
{
printf("****Cong.,You guessed the number ****\n\n");
return 1;
}
}