llltattoolll wrote:
hi im noob here and try learn D language, i try make this example but when run 
have 2 problems.

1) when i show name and lastname show me in two lines and i wanna make in the 
same line.
2) can´t validate option si ( yes ) or no ( no ) and always show the else line.

what happend?
thx

------------------------------------------
code
------------------------------------------
import std.stdio;
import std.string;
import std.c.stdio;



void main()
{

string _nombre, _apellido, _respuesta;
int _edad, _año, _nacimiento;
_año = 2009;

        writefln ("Escribe tu nombre: ");
        _nombre = readln();

        writefln ("Escribe tu apellido: ");
        _apellido = readln();

        writefln ("Hola %s ", _nombre ~= _apellido);

        writefln ("Ingresa el año de tu nacimiento: ");
        scanf ("%d", & _nacimiento);

        _edad = _año - _nacimiento;

        writefln ("Tu edad es %d? \t SI \t NO", _edad);
        _respuesta = readln();

        if ( _respuesta == "si")
        writeln ("Muchas gracias %s", _nombre );
        else
        writeln ("Lo siento %s entonces tienes %d", _nombre, _edad - 1 );
}


Hello,

I think std.stdio.readln() includes the trailing newline. Try this:

    if ( chomp(_respuesta) == "si")

The std.string.chomp() function removes trailing CR and LF characters.

-Lars

Reply via email to