Post Reply 
Apps for the prime.
06-26-2014, 07:46 AM (This post was last modified: 06-26-2014 07:48 AM by Metalnwood.)
Post: #11
RE: Apps for the prime.
Hi Cyrille, I did find that you can make the WAIT function wait for a keyboard, thats good as on first glance it looked like you couldn't WAIT for less than a second and the only other option was a loop running full tack.

This is what I have come up with, I am sure there are more elegant ways to do it with HP's language but I am only an hour and a half in to using this calculator Smile

While working on the input that I have ReadInt I found that the key codes could be a little better, they don't have the ascii codes, I can live with that but it is a shame that the numeric keys are not grouped together, they are in groups of three with gaps in between so the read function is quite long already, without error checking.

Maybe there is a better way but i have not seen it in the manual.

Very basic so far, no real feedback other than a score at the bottom. I might keep a running high score but certainly add the feedback, i.e. correct, wrong - the right answer is .. etc.

I ordered a prime today, I am in New Zealand so I will have to wait for it to arrive from the states, it will probably take 1 1/2 weeks but getting it for $140NZD vs ~$300NZD locally made it a no brainer.

Code:
   
WriteScore(s);
ReadInt(xPos, yPos);

EXPORT multiplication()
BEGIN
  Local Score:=0, x:=0, y:=0, M:=0, Ans:=0;
  CHOOSE(M, "How big do you want to go?", "1", "2", "3", "4", "5", "6", "7", "8");
  Rect();
  TEXTOUT_P("Lets learn our tables up to " + M, 0, 2);

  FOR C FROM 1 TO 5 DO
    x:= floor(random(2, M));
    y:= floor(random(2, M));


    Rect_P(0, 100, 320, 150 );
    TEXTOUT_P("What is " + x +" x " + y,100,100 );
     

    Ans := ReadInt( 140,140);

    if Ans == x*y then
         Score := Score+1;
    end;

    WriteScore(Score);
  

  END;

   return Ans;

END;


WriteScore(s)
BEGIN
  RECT_P(0,200,320, 240);
  TEXTOUT_P("Score : "+ s, 0, 200);
END;

ReadInt(xPos, yPos)
BEGIN
   Local loop:=1, key, Ans :="";

   While loop do

      TEXTOUT_P(Ans, xPos, yPos);
      key := Wait(-1);
      if key == 30 then
        loop := 0;
        break;
      end;
     
      if key < 35 then
        Ans := Ans + (key-25);
        continue;
      end;

      if key < 40 then
        Ans := Ans + (key-33);
        continue;
      end;

      if key < 45 then
        Ans := Ans + (key-41);
        continue;
      end;

      if key == 47 then
        Ans := Ans + "0";
        continue;
      end;     

   END;
   RECT_P(xPos, yPos, xPos+ 50, yPos+50);
   return expr(Ans);
END;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Apps for the prime. - Metalnwood - 06-25-2014, 02:00 AM
RE: Apps for the prime. - Metalnwood - 06-25-2014, 05:47 AM
RE: Apps for the prime. - CR Haeger - 06-25-2014, 05:02 PM
RE: Apps for the prime. - HP67 - 06-25-2014, 07:15 AM
RE: Apps for the prime. - Tugdual - 06-25-2014, 12:22 PM
RE: Apps for the prime. - HP67 - 06-25-2014, 12:26 PM
RE: Apps for the prime. - Michael - 06-25-2014, 12:33 PM
RE: Apps for the prime. - Metalnwood - 06-25-2014, 09:32 PM
RE: Apps for the prime. - Metalnwood - 06-26-2014 07:46 AM
RE: Apps for the prime. - Metalnwood - 06-27-2014, 06:22 AM



User(s) browsing this thread: 1 Guest(s)