# Problem with piece of code in Pascal

Page 1 of 1

## 4 Replies - 490 Views - Last Post: 10 November 2015 - 10:26 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=384329&amp;s=d11cccc35ab7dc890f46575cad3c2676&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Gobias

Reputation: 0
• Posts: 4
• Joined: 10-November 15

# Problem with piece of code in Pascal

Posted 10 November 2015 - 08:41 AM

Hi guys and girls,

I have to write a program which:

1. asks the amount of pocket money you gave your child when they were 5 years old
2. asks how old the child is now
3. gives three options with which to calculate how much pocket money they should receive now.

The three options are:

1. 50% increase every year.
2. \$5 increase every year.
3. Double pocket money after every three years.

Depending on which option I pick the program must then list each change in amount and the age. For example, the second one. If I put \$2 in as initial amount and the new age as 7 the the program would return the following:

At 5 years old: \$5
At 6 years old: \$10
At 7 years old: \$15

If you pick the third option, it should only display at the ages where the amount would change, ie, 5, 8, 11, 14 etc. So if the child is 9 years old it would return:

At 5 years old: \$5
At 8 years old: \$10

The first two I have no problem with. But the last one has me totally stumped. I am pretty sure my instructor wants me to be using a WHILE loop, but I have no idea how to formulate it so that it's efficient.
Can anyone help me out? I'm pretty new to coding and this is the first time I've been this stuck with something. I just can#t see the solution.

Is This A Good Question/Topic? 0

## Replies To: Problem with piece of code in Pascal

### #2 xclite

• I wrote you an code

Reputation: 1282
• Posts: 4,091
• Joined: 12-May 09

## Re: Problem with piece of code in Pascal

Posted 10 November 2015 - 09:04 AM

What have you tried so far? Why worry about efficient at first - I'd focus on getting something working and then decide if there are ways to improve it.

### #3 Gobias

Reputation: 0
• Posts: 4
• Joined: 10-November 15

## Re: Problem with piece of code in Pascal

Posted 10 November 2015 - 09:11 AM

I did manage to get it working actually. I used a series of IF statements and it worked perfectly. My instructor wouldn't accept it and said it had to be more efficient. Sorry, I deleted that code after that so I can't show you it.

My instructor then advised me away from using a FOR loop but said I should use iteration, which leaves WHILE and UNTIL.

### #4 Gobias

Reputation: 0
• Posts: 4
• Joined: 10-November 15

## Re: Problem with piece of code in Pascal

Posted 10 November 2015 - 09:30 AM

I couldn't see how to edit posts so I made a new one for this

I did actually find an older version of the file with the series of IF statements. Here it is:

```writeln('Pocket money at 5 years: ', startmoney:0:2);
if (age < 8) then
begin
end
else
begin
if (age < 11) then
begin
startmoney := startmoney * 2;
end
else
begin
if (age < 14) then
begin
startmoney := startmoney * ( 2 * 2 );
end
else
begin
if (age < 17) then
begin
startmoney := startmoney * ( 2*2*2 );
end
else
begin
if (age < 20) then
begin
startmoney:= startmoney* ( 2*2*2*2 );
end
else
begin
if (age < 22) then
begin
startmoney:= startmoney * ( 2*2*2*2*2 );
end;
end;
end;
end;
end;
end;
writeln('pocket money at ', age, ' years: ', beginmoney:0:2);
end;
```

Now this is actually wrong since it has to print out at 5, 8, 11, 14, 17 and 20 years while this only prints out the amount at 5 years and the amount at the age you enter.

### #5 Gobias

Reputation: 0
• Posts: 4
• Joined: 10-November 15

## Re: Problem with piece of code in Pascal

Posted 10 November 2015 - 10:26 AM

This is hilarious and kinda silly. I've managed to do it. I was using Structorizer and in the time I have been struggling with this there has been an update which has added the ability to set an incrementation in a FOR loop. It was so easy. When I started trying to do this it wasn't there. I just saw it since I was having problems with Structorizer and had to reinstall. Then BOOM! There it is, right in front of my face. Praise the lord!

Anyway, I don't know if I can delete this myself, or if y'all want to just lock it or something, but my problem is solved.