2020年1月28日 星期二

while猜錯繼續做(成立),不成立才結束

#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;
}

沒有留言:

張貼留言

algorithm

 #include <iostream> #include <string.h> using namespace std; int main(int argc, char** argv)  { for(int j=2;j<=100;j++)//j...