#include <stdio.h>
int main()
{
int ans = 4;
int guess;
printf("Please enter your guess:");
scanf("%d",&guess);
while(guess != ans)
{
if(guess>ans)
{
printf("Too large!\n");
}
else
{
printf("Too small!\n");
}
printf("Please enter your guess:");
scanf("%d",&guess);
}
printf("Correct!\n");
return 0;
}
---------------------------------------------------------------------
#include <stdio.h>
int main()
{
int ans = 4;
int guess;
do
{
printf("Please enter your guess:");
scanf("%d",&guess);
if(guess>ans)
{
printf("Too large!\n");
}
else if(guess<ans)
{
printf("Too small!\n");
}
else
{
printf("Correct!\n");
}
}
while(guess != ans) ;//猜錯繼續做(成立),不成立才結束
return 0;
}
沒有留言:
張貼留言