Hôm nay lại nhờ các tiền bối tìm ra lỗi trong trò chơi nay giúp . Trò chơi này em tạo từ câu for loop . Lỗi cụ thể là khi đoán số dù số đoán không chính xác nhưng nó vẫn nói là em đã chọn đúng.@@
Em xin quẳng code vào đây nhé:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int sobimat=0,sodoan=0;
printf("Hello:3 Hom nay ta se choi mot tro choi ten la \"Doan so\" \n");
printf("Hai ban da san sang chua,ta bat dau nhe \n");
printf("Ban thu nhat hay lua mot so bi mat: \n"); scanf("%d",&sobimat);
printf("Ok.Gio den ban thu hai hay doan so bi mat do nao: \n"); scanf("%d",&sodoan);
for(sodoan;sodoan<sobimat;)
{
printf("Oh no,so nay lai be hon so bi mat.Hay chon lai nhe=) \n"); scanf("%d",&sodoan);
}
for(sodoan;sodoan>sobimat;)
{
printf("Oh no,so nay lai lon hon so bi mat.Hay chon lai nhe=) \n"); scanf("%d",&sodoan);
}
printf("Oh yes! Ban that tuyet voi. Ban da doan dung so bi mat la %d",sobimat);
return 0;
}
Và đây là khi chạy chương trình:
Hello:3 Hom nay ta se choi mot tro choi ten la "Doan so"
Hai ban da san sang chua,ta bat dau nhe
Ban thu nhat hay lua mot so bi mat:
567
Ok.Gio den ban thu hai hay doan so bi mat do nao:
25
Oh no,so nay lai be hon so bi mat.Hay chon lai nhe=)
334
Oh no,so nay lai be hon so bi mat.Hay chon lai nhe=)
678
Oh no,so nay lai lon hon so bi mat.Hay chon lai nhe=)
88
Oh yes! Ban that tuyet voi. Ban da doan dung so bi mat la 567
Process returned 0 (0x0) execution time : 19.725 s
Press any key to continue.