I think readf("%s") reads everything available. readf(" %s\n") might help but personally, I say avoid readf. Just use readln and to!int instead auto line = readln(); if(line.length == 0) writeln("please enter a number"); age = to!int(line); to is from import std.conv