Q Basic program for the 12 days of Christmas

Discuss whatever you want here--both QB and non-QB related. Anything from the DEF INT command to the meaning of life!

Moderators: Pete, Mods

Post Reply
kevin
Newbie
Posts: 1
Joined: Thu Feb 02, 2006 6:07 pm

Q Basic program for the 12 days of Christmas

Post by kevin »

Help!...Novice user here...suddenly need a Q Basic program for

The Twelve Days of Christmas Price List

Partridge in a pear tree 27.50
Turledove 25.00

etc. etc..Request an integer from 1 to 12 and then lists the gifts for that day along with that day's cost. On the nth day, the n gifts are 1 partridge in a pear tree, 2 turtledoves.......n of the nth item. Also program should also give the total cost of all twelve days...

Can anybody point me in the right direction?..or give me a bare bones format so I can extrapolate?...On-line college student here who is woefully failing in writing this program...many thanks..K
Kevin Nally
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post by Rattrapmax6 »

Lemme be as kind to ask this... What do you know about programing? And what do you not understand about this?
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
User avatar
Zim
Veteran
Posts: 98
Joined: Mon Dec 05, 2005 4:31 pm
Location: Wisconsin, USA
Contact:

A start

Post by Zim »

Code: Select all

input n
for i=n to 1 step -1
  print i
next i
given a number, will print a list of numbers from that point counting down to 1.

For your program, you have to decide what you want done for each day, and code that in, in place of the "print i".

That's a start. Was this due before Christmas??
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo »

Kevin, I get the feeling that this problem is some kind of a homework assignment, and we are not supposed to do people's homework. So, I'm not going to post the code for this program, but I can give you the following design pointers:

1) You need to set up a string array, using a DIM statement, having 1 to 12 elements to hold the descriptions of your 12 gifts.

2) You also need to set up an array of type single to hold the 12 prices of your gifts. It needs to be single because you have decimal values.

3) You need to put 12 pieces of data into each of the above arrays --- 12 gift descriptions into the description array, and 12 prices into the price array. You can do this with DATA statments, or you can just code 12 lines of code for each array, placing the corresponding data into the 12 elements of each array.

4) Define a totalcost variable as single. That's the end of the initialization section of your program.

5) Now you can ask the user for a number from 1 to 12. You should validate this number making sure that it's from 1 to 12, otherwise the rest of the program will go nuts. If it's invalid, print a little message and go back to ask him for a new number.

6) Make a FOR loop that increments an index variable from 1 to 12. Within the loop, code the following:
6a) Add the price of the element of the price array pointed to by the index, to the totalcost.
6b) Print the same price to the screen immediately followed by 2 spaces and then the corresponding description element pointed to by the index, from the description array. If the prices do not occupy the same number of digits, then you may have to use a PRINT USING statement so that the prices and descriptions line up.
6c) Now compare the user entered number to the index. If they are equal, then you're finished with the FOR loop, get out with an EXIT FOR.
6d) This is the end of your FOR loop (like NEXT INDEX).

7) You got here via the EXIT FOR.
Now print out the totalcost, adding a description of " Total Cost"

8) You're done, terminate the program with an END or SYSTEM.

Good luck!
*****
Post Reply