#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int soBiMat=0, soHientai=0, tieptucGame=1, Level=0, i=0, Kieuchoi=0,Songuoinhap =0, Choihaynghi=1;
while(Choihaynghi)
{
printf("Moi chon kieu choi\n");
printf("Kieu 1: Choi voi may\n");
printf ("Kieu 2: Choi voi ban\n");
scanf("%d", &Kieuchoi);
switch(Kieuchoi)
{
case 1:
printf("Ban da chon choi voi may\n");
break;
case 2:
printf("Ban da chon choi voi ban\n");
break;
default:
printf("Khong co kieu choi do\n");
break;
}
if(Kieuchoi==1)
{
printf("Moi ban chon cap do choi\n");
printf("Level 1: tu 1 den 10\n");
printf("Level 2: tu 1 den 100\n");
printf("Level 3: tu 1 den 1000\n");
scanf("%d", &Level);
switch(Level)
{
case 1:
printf("Ban da chon level %d\n\n", Level);
srand(time(NULL));
soBiMat=(rand()%(10))+1;
break;
case 2:
printf("Ban da chon level %d\n\n", Level);
srand(time(NULL));
soBiMat=(rand()%(100))+1;
break;
case 3:
printf("Ban da chon level %d\n\n", Level);
srand(time(NULL));
soBiMat=(rand()%(1000))+1;
break;
default:
printf("Ban da chon sai level\n");
break;
}
/***************************************************************/
do
{
i=i++;
printf("So can tim la bao nhieu?\n");
scanf("%d", &soHientai);
if (soHientai<soBiMat)
{
printf("Nho hon so bi mat\n");
}
else if (soHientai>soBiMat)
{
printf("Lon hon so bi mat\n");
}
else
{
printf("Chuc mung! Ban da tim duoc so bi mat\n");
}
}while(soHientai!=soBiMat);
printf("Ban da tim duoc voi %d lan nhap\n", i);
}
else
{
printf("Nguoi phai doan so nham mat vao\n");
printf("Moi nguoi chon so nhap so bi mat khong qua 1000\n");
scanf("%d", &Songuoinhap);
printf("Nguoi doan bat dau choi nao\n");
if(Songuoinhap<=10)
printf("So ban can tim tu 1 den 10\n");
else if (Songuoinhap<=100)
printf("So ban can tim tu 1 den 100\n");
else if (Songuoinhap<=1000)
printf("So ban can tim tu 1 den 10000\n");
do
{
i=i++;
printf("So can tim la bao nhieu?\n");
scanf("%d", &soHientai);
if (soHientai<soBiMat)
{
printf("Nho hon so bi mat\n");
}
else if (soHientai>soBiMat)
{
printf("Lon hon so bi mat\n");
}
else
{
printf("Chuc mung! Ban da tim duoc so bi mat\n");
}
}while(soHientai!=soBiMat);
printf("Ban da tim duoc voi %d lan nhap\n", i);
}
printf("Nhan 1 de choi tiep, Nhan 0 de thoat\n");
scanf("%d", &Choihaynghi);
}
return 0;
}