Recent

Author Topic: Hi can someone help me with converting this pseudocode to pascal please  (Read 2162 times)

Myaaaa

  • Guest
START
   Set total 🡨 0
   Set revenue 🡨 0
   Set fare 🡨 7.50
   PRINT “Enter number of passengers”
   SAVE passenger
   WHILE passenger is not equal to 0 DO
      Set revenue 🡨 passenger * fare
      Set total 🡨 total + revenue
      PRINT “Enter number of passengers to continue or 0 to end program”
      SAVE passenger
   End while
   PRINT “The total revenue is $”, total
STOP

engkin

  • Hero Member
  • *****
  • Posts: 2872
Show us what you did first. We can guide you, but we will not write you assignment for you.

Myaaaa

  • Guest
Code: [Select]
Program Revenue;
Uses crt;
Const
       Total = 0;
        Revenue = 0;
        Fare = 7.50;
Var
    Passengers, total;
Begin
Clrscr;
Write (‘Enter number of passengers’);
ReadIn(passenger);
While(passenger <> 0 DO);
      Begin
Revenue := passenger * fare;
Total := total + revenue;
Write(‘Enter number of passengers(enter 0 to stop);
ReadIn (passenger);
End;
Write(‘The total revenue is $”, total’);
End.
« Last Edit: May 21, 2021, 10:19:24 pm by Myaaaa »

engkin

  • Hero Member
  • *****
  • Posts: 2872
Please modify your post and put your code inside code section. You get a code section when you press the # button above the smilies.

You declared Total, Revenue, and Fare as constants. That is not correct. Their values might change, make them variables, and assign their initial values in the code at the beginning.

speter

  • Full Member
  • ***
  • Posts: 217
Myaaaa, that's a really good effort!

In addition to engkin's comments, I have a couple of suggestions:

1) Change the variable declaration of "passengers, total;" to include the variable type (and an initial value). I'd suggest going with
Code: Pascal  [Select][+][-]
  1. var
  2.   total : single = 0.0;
  3.   revenue : single = 0.0;
  4.   passengers : integer;

2) Your while statement is slightly messed up. I'd suggest
Code: Pascal  [Select][+][-]
  1. while (passenger <> 0) do

3) The second last line should use "writeln" not "write".

4) Finally, you might want to consider "cleaning up" your indenting; I'd suggest indenting each level by 2 spaces...

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

Laz 2.0.10 / FPC 3.2.0 / Windows 10 (64bit)

jamie

  • Hero Member
  • *****
  • Posts: 4753
I think the problem could be in the way the results is getting displayed and the misuse of the single quotes.

Code: Pascal  [Select][+][-]
  1.  
  2. Writeln('The total revenue is $', total:10:2);
  3.  
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018