Yes or No Options

Alex via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 28 04:00:56 PDT 2015


So I now combined a few of the options here and got this, which 
finally works:

import std.stdio;
import std.string;
import std.random;

void main()
{
	while (true) {
	string yesno;
	int weiter;
	char[] uschi;
	
	write("Press ENTER to roll the dice!");
	readln(uschi);
	if (uschi == "\n") {
	auto rng = uniform(1, 6);
	writeln(rng);
	
	if (rng < 4) {
		writeln("You won!");
	}
	else if ((rng >= 4) && (rng <= 6)) {
		writeln("I won!");
	}
	else if (rng > 6){
		writeln("ERROR: Invalid Value");
	}
	
	writeln("Do you want to play again? Y/N?");
	yesno = readln();
	if (yesno.toLower() != "y\n") {
		writeln("Damn it");
				break;
	}
     }
	}
}




Thank you ! :)


More information about the Digitalmars-d-learn mailing list