由于不会D语言的随机数,干脆core.stdc.stdlib
调用stdlib.h
这里mark一下,类型转换是cast(D语言类型)
NULL
不能用,要用null
import std.stdio;
import core.stdc.stdlib;
import core.stdc.time;
import core.stdc.stdio;
int main(string[] args)
{
srand(cast(uint)time(null));
int a = rand()%100,b,flag = 4;
writeln("Hello !Let's play a game");
writeln("Now I have a number,do you know it?");
while(flag--){
writeln("If you know it,please tell me it.");
writeln("You have ",flag," times");
readf("%d
",&b);
if(b > a){
writeln("No,it's too big");
continue;
}
if(b < a){
writeln("No,it's too small");
continue;
}
if(a == b){
writeln("Yes!That is");
break;
}
}
writeln("Game End!A is ",a);
return 0;
}