à bạn ơi cho mình hỏi luôn mình tạo mức độ khó của game thông qua cái bảng menu chọn mức 1 thì từ 1 dến 100 , mức 2 từ 1 đến 1000 , mức 3 từ 1 đến 10000 . Dùng lệnh switch sửa mãi k đc :v
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int sobimat=0,sodudoan=0,bodem=1,choitiep,gioihan,luachon=0;
const int min=1;
printf(" lua chon muc choi\n");
printf(" Muc 1 : tu 1 den 100\n");
printf(" Muc 2: tu 1 den 1000\n");
printf("Muc 3: tu 1 den 10000\n");
printf(" Lua chon cua ban : ");
scanf("%d",&luachon);
switch(luachon)
{
case 1:
while(choitiep!=0)
{
//Khoi tao sobimat
srand(time(NULL));
sobimat=(rand()%(gioihan-min+1))+min;
printf("Sobi mat la : %d\n",sobimat);
//Khoi tao bodem
gioihan=100;
do
{
printf("Nhap so du doan: ");
scanf("%d",&sodudoan);
if (sodudoan<sobimat)
{printf("lon hon\n");
bodem+=1;
printf("bo dem la %d\n",bodem);}
else if(sodudoan>sobimat)
{printf(" nho hon\n");
bodem+=1;
printf("bo dem la %d\n",bodem);}
else
printf("Chuc mung ban da doan dung so bi mat sau %d lan\n",bodem);
}
while(sodudoan!=sobimat);
printf(" Cam on ban da tham gia tro choi\n");
printf("Moi nhap so khac voi so 0 de choi tiep : ");
scanf("%d",&choitiep);
}
break;
case 2:
while(choitiep!=0)
{
//Khoi tao sobimat
srand(time(NULL));
sobimat=(rand()%(gioihan-min+1))+min;
printf("Sobi mat la : %d\n",sobimat);
//Khoi tao bodem
gioihan=1000;
do
{
printf("Nhap so du doan: ");
scanf("%d",&sodudoan);
if (sodudoan<sobimat)
{printf("lon hon\n");
bodem+=1;
printf("bo dem la %d\n",bodem);}
else if(sodudoan>sobimat)
{printf(" nho hon\n");
bodem+=1;
printf("bo dem la %d\n",bodem);}
else
printf("Chuc mung ban da doan dung so bi mat sau %d lan\n",bodem);
}
while(sodudoan!=sobimat);
printf(" Cam on ban da tham gia tro choi\n");
printf("Moi nhap so khac voi so 0 de choi tiep : ");
scanf("%d",&choitiep);
}
break;
case 3:
while(choitiep!=0)
{
//Khoi tao sobimat
srand(time(NULL));
sobimat=(rand()%(gioihan-min+1))+min;
printf("Sobi mat la : %d\n",sobimat);
//Khoi tao bodem
gioihan=10000;
do
{
printf("Nhap so du doan: ");
scanf("%d",&sodudoan);
if (sodudoan<sobimat)
{printf("lon hon\n");
bodem+=1;
printf("bo dem la %d\n",bodem);}
else if(sodudoan>sobimat)
{printf(" nho hon\n");
bodem+=1;
printf("bo dem la %d\n",bodem);}
else
printf("Chuc mung ban da doan dung so bi mat sau %d lan\n",bodem);
}
while(sodudoan!=sobimat);
printf(" Cam on ban da tham gia tro choi\n");
printf("Moi nhap so khac voi so 0 de choi tiep : ");
scanf("%d",&choitiep);
}
break;
default :
printf(" Chi duoc chon 1 trong 3 truong hop ");
break;
}
system("pause");
return 0;
}