Jump to content

Re: Pseudocode Tutorial: The Basics - spawned question

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
11 replies to this topic

#1
charlote

charlote

    Newbie

  • Members
  • PipPip
  • 29 posts
Need help with pseudocode problem:

Here is the question?
Secondhand Rose Resale shop is having a 7 day sale during which the price of any unsold item drops 10% each day. The inventory File includes an item number, description, and original price on day one. For example, an item that costs $10.00 on the 1st day costs 10% less, or $9.00, on the 2nd day. On the 3rd day the same item is 10% less than $9.00 or $8.10. Design an application that reads inventory records and produces a report that shows the price of every item on each day, one through seven.

What I have done so far is :

Open inventory File
Read one record in inventory File
while there are still records in the inventory file

Price = record.Original_Price
for i = 1 to 7
print price for day, i
print record_ItemNumber, description, price
price = price * 0.9


Am I doing it right.? The problem is I don't want to use For Loop here.
Can anyone help me with this?
Thanks,
Charlotte

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Why don't you want to use for loops? It's the natural option.

Moved to its own thread.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
charlote

charlote

    Newbie

  • Members
  • PipPip
  • 29 posts
Hi!

ITA. For loop would be the best option.
Just trying different options. Moreover I have been asked to use while loop..

In that case, would this be correct?

while i<=7
do(statement)
endwhile

my question is if I use the "price = price*0.9" would it work? would it automatically take 2nd day's price to calculate 3rd day's discount?

Thank you,
Charlotte

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Yes, that would work. Just be sure to increment i as part of "statement"
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
charlote

charlote

    Newbie

  • Members
  • PipPip
  • 29 posts
Thank you!

Charlote

#6
charlote

charlote

    Newbie

  • Members
  • PipPip
  • 29 posts
WingedPanther,

If I need some help with flowcharts, where do I look? I am having trouble with arrays actually. Can you help?

#7
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
Post any questions in the forum and tons of members would be happy to assist you with your flow chart and array problem.

What exactly are you having issues with?

#8
charlote

charlote

    Newbie

  • Members
  • PipPip
  • 29 posts
here is my code,
start
  num teamNum
  string firstName
  string lastName
  num SIZE = 5
  string teams[SIZE] = "Goal Getters", "The Force", "Top Guns", "Shooting Stars", "Midfield Monsters"
  read firstName, lastName, teamNum
  while not eof
        if teamNum ?=1 AND teamNum <= SIZE then
             print firstName, lastName, teamNum, teams[teamNum-1]
        else 
             print "Invalid team Number"
        endif
        get firstName, lastName, teamNum
    endwhile

(This code is to read the data from the file and to create a report that lists each player along with his team number and team name)
I want to modify this one to count the total number of players in each team (using the read data) and display/print list of players in each team( display /print total count in each team and team name)
how do I use subscript in print module? Do I need to use individual team name?


To count I actually did the following:
num teamCount [SIZE] = 0
  If teamNum >= 1 AND teamNum<= SIZE then
       teamCount[teamNum-1] = teamCount[teamNum-1] +1
  else
     print "Invalid team number"
  endif
  read firstName,lastName, teamNum
endwhile
while teamNum<SIZE
   print teamNum+1, teamCount[teamNum], teams???(this is where I don't know how to display/print teamName?)
   teamNum = teamNum + 1
 endwhile
stop

Edited by WingedPanther, 07 March 2010 - 05:42 PM.
add code tags


#9
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You've got an endwhile without a while...
I think you need a two-dimensional array to hold the team members. Do you have a spec on the file format?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#10
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You've got an endwhile without a while...
I think you need a two-dimensional array to hold the team members. Do you have a spec on the file format?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#11
charlote

charlote

    Newbie

  • Members
  • PipPip
  • 29 posts
I am just learning the basics(pseudo code and flowchart). I don't have any spec on file format. I think "endwhile" was my mistake.

num teamCount [SIZE] = 0
read firstName, lastName, teamNum
while not eof
If teamNum >= 1 AND teamNum<= SIZE then
teamCount[teamNum-1] = teamCount[teamNum-1] +1
else
print "Invalid team number"
endif
read firstName,lastName, teamNum
endwhile
while teamNum<SIZE
print teamNum+1, teamCount[teamNum], teams???(this is where I don't know how to display/print teamName?)
teamNum = teamNum + 1
endwhile
stop

Would this be correct one?

Thanks for your quick reply

I forgot to ask how do I upload the flowchart file? Can I just attach the VISIO files here?

Edited by Vswe, 08 March 2010 - 05:11 AM.
Don't double post, edit instead.


#12
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Please use code tags (the # button) and indentation to make your pseudocode readable.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog