vendredi 29 janvier 2016

How to compare strings in ada 95

I'm just strating to learn Ada 95 and I'm having some problems with comparing strings.

Here's the code:

    with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; 
with Ada.Command_Line;
with Ada.Strings.Unbounded;

procedure Test1 is

vad : String(1..9);
Amount : Integer;
Main : Integer;
Second : Integer;
Third : Integer;

begin
   Main := 1;
   Second := 0;
   Third := 0;

   Put("What do you want to do?");
   New_Line(1);
  Get(vad);
  New_Line(1);

  if Vad  = "fibonacci" then
     Put("How long do you want the sequence to be");
     New_Line(1);

     Get(Amount);
     New_Line(1);

      Amount := Amount -1;



      for I in 1 .. Amount loop
     Put(Main); 
     New_Line(1);
     --Put(" ");
     Third := Second;
     Second := Main;

     Main := (Second + third);
      end loop;

      New_Line(2);

  elsif Vad = "two" then
     Put("How long do you want the sequence to be?");
     New_Line(1);
     Get(Amount); 
     New_Line(1);
     for U in 1 .. Amount loop
    Put(U * 2);
    Put(", ");
     end loop;


  else
   Put("ok");

  end if;

end Test1;

As it is now, the if statement recognises when I type fibonacci, but when I type two it just goes to the 'else' part of the code.

Any ideas what might be wrong?

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire