由于不会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;
}

相关文章:

  • 2021-08-30
  • 2022-12-23
  • 2021-11-30
  • 2021-11-30
  • 2021-11-30
  • 2021-05-24
  • 2021-08-14
猜你喜欢
  • 2021-11-30
  • 2021-11-02
  • 2021-05-05
  • 2022-12-23
  • 2022-12-23
  • 2021-07-18
  • 2021-11-04
相关资源
相似解决方案