### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

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

#### Myaaaa

• Guest
##### Hi can someone help me with converting this pseudocode to pascal please
« on: May 21, 2021, 07:33:17 pm »
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: 2924
##### Re: Hi can someone help me with converting this pseudocode to pascal please
« Reply #1 on: May 21, 2021, 07:54:28 pm »
Show us what you did first. We can guide you, but we will not write you assignment for you.

#### Myaaaa

• Guest
##### Re: Hi can someone help me with converting this pseudocode to pascal please
« Reply #2 on: May 21, 2021, 09:05:14 pm »
Code: [Select]
`Program Revenue;Uses crt;Const       Total = 0;        Revenue = 0;        Fare = 7.50;Var    Passengers, total; BeginClrscr; 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: 2924
##### Re: Hi can someone help me with converting this pseudocode to pascal please
« Reply #3 on: May 21, 2021, 09:14:50 pm »
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: 222
##### Re: Hi can someone help me with converting this pseudocode to pascal please
« Reply #4 on: May 22, 2021, 02:46:08 am »
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: 4841
##### Re: Hi can someone help me with converting this pseudocode to pascal please
« Reply #5 on: May 22, 2021, 12:40:14 pm »
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