Yes or No Options
Alex via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jul 27 08:50:10 PDT 2015
Hey guys!
I am super new to programming and still trying to learn the very
basics via a book that I bought.
My problem is the following:
import std.stdio;
import std.string;
void main()
{
char[] yesno;
write("Roll the dice: Enter a number!");
int dieNumber;
readf(" %s", &dieNumber);
if (dieNumber < 4) {
writeln("You won!");
}
else if ((dieNumber >= 4) && (dieNumber <= 6)) {
writeln("I won!");
}
else if (dieNumber > 6){
writeln("ERROR: Invalid Value");
}
writeln("Do you want to play again? Y/N?");
readln(yesno);
if (yesno == "Y") {
writeln("Let's go again!");
}
}
The program quits after "writeln("Do you want to play again?
Y/N?");"
It ignores readln.
Furthermore: What I am actually trying to do is: If I type "Y",
the programm should just rerun from the beginning.
I am really new to programming and there is probably a much
easier way but this is all I know to this point.
Thanks in advance!
More information about the Digitalmars-d-learn
mailing list