源代碼如下:
創(chuàng)新互聯(lián)建站長(zhǎng)期為上千家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為林甸企業(yè)提供專業(yè)的成都網(wǎng)站建設(shè)、成都做網(wǎng)站,林甸網(wǎng)站改版等技術(shù)服務(wù)。擁有十載豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。
#include
#include
#include//生成隨機(jī)函數(shù)起點(diǎn)時(shí)用到time.h
int main()
{
int number1 = 0, choice = 0, number2 = 0;
printf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");//界面設(shè)置
printf("$$$$$ 歡 迎 來(lái) 到 $$$$$\n");
printf("$$$$$ 猜 數(shù) 字 游 戲 $$$$$\n");
printf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
printf(" 1.進(jìn)入游戲\n");
printf(" 2.退出游戲\n");
scanf("%d", &choice);
srand((unsigned int)time(NULL));//設(shè)置隨機(jī)數(shù)起點(diǎn)
while (choice == 1)
{
printf("請(qǐng)輸入所猜的數(shù):\n");
scanf("%d", &number2);
number1 = rand() % 100;
while (1)
{
if (number2 == number1)
{
printf("666 恭喜你答對(duì)了!");
printf("\n1.再玩一次\n2.退出游戲\n");
scanf("%d", &number2);
if (number2 == 1)
break;
if (number2 == 2)
return 0;
}
if (number2 < number1)
{
printf("\n猜小了!\n");
scanf("%d", &number2);
}
if (number2 > number1)
{
printf("\n猜大了!\n");
scanf("%d", &number2);
}
}
}
while(choice == 2)
{
return 0;
}
system("pause");
return 0;
}
運(yùn)行結(jié)果: