write a program uses nested if statments? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

write a program uses nested if statments?

herper147herper147 Posts: 5Member
write a program that asks for three names and then uses nested if statments to display them in alphabetical order.

plz can anyone figure this out i have spent a few hours trying to figure it out

Comments

  • ActorActor Posts: 438Member
    : write a program that asks for three names and then uses nested if
    : statments to display them in alphabetical order.
    :
    : plz can anyone figure this out i have spent a few hours trying to
    : figure it out
    :
    [code]
    {
    not a very elegant way of doing it but it should work
    }
    program nestedif ;

    var
    name : array[1 .. 3] of string ;

    begin
    {
    get the three names -- we could us a loop here
    }
    write ('Enter first name ') ;
    readln (name[1]) ;
    write ('Enter second name ') ;
    readln (name[2]) ;
    write ('Enter third name ') ;
    readln (name[3]) ;

    writeln (name[1]) ;
    writeln (name[2]) ;
    writeln (name[3]) ;
    {
    sort and print
    }
    if (name[1] <= name[2]) and (name[1] <= name[3]) then begin
    {
    name[1] is first
    }
    writeln (name[1]) ;
    if name[2] <= name[3] then begin
    writeln (name[2]) ;
    writeln (name[3])
    end
    else begin
    writeln (name[3]) ;
    writeln (name[2])
    end
    end
    else if (name[2] <= name[1]) and (name[2] <= name[3]) then begin
    {
    name[2] is first
    }
    writeln (name[2]) ;
    if name[1] <= name[3] then begin
    writeln (name[1]) ;
    writeln (name[3])
    end
    else begin
    writeln (name[3]) ;
    writeln (name[1])
    end

    end
    else if (name[3] <= name[1]) and (name[3] <= name[2]) then begin
    {
    name[3] if first
    }
    writeln (name[3]) ;
    if name[1] <= name[2] then begin
    writeln (name[1]) ;
    writeln (name[2])
    end
    else begin
    writeln (name[2]) ;
    writeln (name[1])
    end
    end
    end.


    [/code]
Sign In or Register to comment.