digitalmars.D - Yes or No Options
- Alex (35/35) Jul 27 2015 Hey guys!
 - John Colvin (4/8) Jul 27 2015 This isn't the right place for this sort of question, please use
 - Brad Anderson (5/13) Jul 27 2015 As John said, the Learn forum is a better spot for this but as
 
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!
 Jul 27 2015
On Monday, 27 July 2015 at 15:40:56 UTC, Alex wrote:Hey guys! I am super new to programming and still trying to learn the very basics via a book that I bought. [...]This isn't the right place for this sort of question, please use http://forum.dlang.org/group/learn, I'm sure someone will be able to help you there.
 Jul 27 2015
On Monday, 27 July 2015 at 15:40:56 UTC, Alex wrote:
 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!
As John said, the Learn forum is a better spot for this but as 
far as your problem goes, look into the do-while loop construct. 
It's perfect for this situation. You could also use "break" 
inside of an infinite while loop. Good luck.
 Jul 27 2015








 
 
 
 "John Colvin" <john.loughran.colvin gmail.com> 