Post Reply 
PPL PRINT Function
07-26-2015, 10:51 AM
Post: #1
PPL PRINT Function
I am on my third day with my new Prime, and I'm loving it.

To try out PPL for the first time, I entered one of my favorite programs - how many ways to make $1.00 from change. It's a simple set of four nested FOR-NEXT statements with a test in the middle for whether or not the current combination of pennies, nickels, dimes and quarters add up to 100.

In the middle, I like to also print out those combinations that add up to 100. Usually, something like this: P: w N: x D: y Q: z all on one line for each combination.

I have not yet found how to make the PPL PRINT function print anything more than one thing on a line, so I am getting this instead:
P: w
N: x
D: y
Q: z

This is not very display friendly as everything is run together vertically.

Can anyone tell me how to PRINT more than one thing on a line?

Code:
EXPORT Dollar()
BEGIN
PRINT();
C:=0;
FOR P FROM 0 TO 100 STEP 5 DO
FOR N FROM 0 TO 20 DO
FOR D FROM 0 TO 10 DO
FOR Q FROM 0 TO 4 DO
IF P+(N*5)+(D*10)+(Q*25)=100 THEN C:=C+1;
PRINT("P:" +P);
PRINT("N:" +N);
PRINT("D:" +D);
PRINT("Q:" +Q)
END;
END;
END;
END;
END;
MSGBOX("ways_to_make_a_dollar="+C)
END;

Thanks very much, in advance, for your patience and advice.

smp
Find all posts by this user
Quote this message in a reply
07-26-2015, 11:16 AM (This post was last modified: 07-26-2015 11:35 AM by DrD.)
Post: #2
RE: PPL PRINT Function
One way to do it (click in terminal screen to end, or wait for timeout):

Code:

EXPORT Dollar()
BEGIN
  PRINT();
  C:=0;

  FOR P FROM 0 TO 100 STEP 5 DO
    FOR N FROM 0 TO 20 DO
      FOR D FROM 0 TO 10 DO
        FOR Q FROM 0 TO 4 DO
          IF P+(N*5)+(D*10)+(Q*25)=100 THEN C:=C+1;
//PRINT("P:" +P);
//PRINT("N:" +N);
//PRINT("D:" +D);
//PRINT("Q:" +Q);
          print("P:" +P + "  " + "N:" +N +"  " + "D:" +D + "  " +"Q:" +Q);
          END;  // ends if
        END;  // ends Q
      END;  // ends D
    END;  //  ends N
  END;  //  ends P

  wait(-1);
  return MSGBOX("ways_to_make_a_dollar="+C);
END;
Find all posts by this user
Quote this message in a reply
07-26-2015, 01:18 PM
Post: #3
RE: PPL PRINT Function
Thank you *very* much, DrD.

I had not yet figured out why the "+" was needed to get the second item into my PRINT statements, but now it makes perfect sense.

Thanks again for your patience and attention.

smp
Find all posts by this user
Quote this message in a reply
Post Reply 




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