D语言-随机数游戏

由于不会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\n",&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;
}
posted @ 2020-02-18 15:26  SD!LTF  阅读(...)  评论(...编辑  收藏