Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Computer Store with turing
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
AiR




PostPosted: Tue May 25, 2004 6:47 pm   Post subject: Computer Store with turing

For a school project I have to make a program which is a store that sells anything I want since I am already selling computer mods I decided to use those. I am having a problem at getting the tax if some of you may help me, it would be appreciated. Also please give comments on how I can improve this program.
Quote:
var password := 0214
var stock1, stock2, stock3, stock4, stock5 := 20
var answer, choice : string
var cart := 0
var quantity : int
var colr : int := 32
var money, change : int
var tax:= cart *.15
loop
loop
loop
colorback (white)
cls
color (black)
put " "
put "Please enter password."
color (white)
get password
color (black)
if password not= 0214 then
put " "
put "That is incorrect access is denied. "
elsif password = 0214 then
exit
end if
end loop

put " "
put "Welcome to Brightling, one of the world's top seller in computer modifications."
loop
put " "
put "Would you like to purchase an item(s) Yes [y] or No [n]?"
get answer
if answer = "No" or answer = "no" or answer = "N" or answer = "n" then
put "Good bye have a nice day."
loop
end loop
elsif answer = "yes" or answer = "Yes" or answer = "Y" or answer = "y" then
exit
end if
end loop

for a : -maxy .. maxy
if colr < 55 then
colr += 1
else
colr := 32
end if
drawarc (maxx div 2, a - 25, maxx div 2, maxy, 0, 180, black)
drawarc (maxx div 2, a, maxx div 2, maxy, 0, 180, colr)
delay (5)
end for
colorback (black)
cls
color (white)
put " "
put "Which item(s) would you like to purchase? "
put "a) Cathode Lights / Stock:", stock1, " / Price: $20"
put "b) Computer Cases / Stock:", stock2, " / Price: $200"
put "c) Fan Grills / Stock:", stock3, " / Price: $20"
put "d) Lazer LED Lights / Stock:", stock4, " / Price: $30"
put "e) Window Appliques / stock:", stock5, " / Price: $10"
loop
get choice
if choice not= "a" and choice not= "b" and choice not= "c" and choice not= "d" and choice not= "e" and choice not= "A" and choice not= "B" and choice not= "C" and choice not= "D" and
choice
not= "E" then
put "You have entered an invalid choice please choose an item"
put "from the list using a,b,c,d, or e."
% cathode lights
elsif choice = "a" or choice = "A" then
put "You have chosen Cathode lights which is 20 dollars for one."
put "How many would you like to buy?"
get quantity
stock1 := stock1 - quantity
cart := quantity * 20 + cart
put "Would you like to choose another item?"
get answer
if answer = "no" then
exit
elsif answer = "yes" then
put " "
end if
%Computer Cases
elsif choice = "b" or choice = "B" then
put "You have chosen a Computer Case which is 200 dollars for one."
put "How many would you like to buy?"
get quantity
stock2 := stock2 - quantity
cart := quantity * 200 + cart
put "Would you like to choose another item?"
get answer
if answer = "no" then
exit
elsif answer = "yes" then
put " "
end if
%Fan grills
elsif choice = "c" or choice = "C" then
put "You have chosen a Fan Grill which is 20 dollars for one."
put "How many would you like to buy?"
get quantity
stock3 := stock3 - quantity
cart := quantity * 20 + cart
put "Would you like to choose another item?"
get answer
if answer = "no" then
exit
elsif answer = "yes" then
put " "
end if
elsif choice = "d" or choice = "D" then
put "You have chosen a Lazer LED Light which is 30 dollars for one."
put "How many would you like to buy?"
get quantity
stock4 := stock4 - quantity
cart := quantity * 30 + cart
put "Would you like to choose another item?"
get answer
if answer = "no" then
exit
elsif answer = "yes" then
put " "
end if
elsif choice = "e" or choice = "E" then
put "You have chosen a Window Applique which is 10 dollars for one."
put "How many would you like to buy?"
get quantity
stock5 := stock5 - quantity
cart := quantity * 10 + cart
put "Would you like to choose another item?"
get answer
if answer = "no" then
exit
elsif answer = "yes" then
put " "
end if
end if
exit
end loop

put "The total amount you have to pay is ", cart * .15 + cart, " dollars"
put "Would you like to pay with cheque, cash, or credit card."
get choice
if choice = "cash" then
put "How much will you be paying?"
get money
cart := cart + tax Can't seem to get this going
change := money - cart
put "Your total change change will be ", change
end if
end loop

end loop



Also in addition I would like to add if the stock = 0 I would tell them the product is sold out.
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Tue May 25, 2004 7:03 pm   Post subject: (No subject)

change this line
code:

cart := cart + tax

to this
code:

cart := cart + round (tax)

and it should work.
previously you were trying to add a real number (tax) to an integer (cart) and it wouldn't let you.

I haven't looked through all of your code, but I do have one comment:
where you have this:
code:

            if answer = "No" or answer = "no" or answer = "N" or answer = "n" then
                put "Good bye have a nice day."
                loop
                end loop

I'm not sure if you really want to contain the user in an infinate loop of nothingness, but you may consider replacing
code:

loop
end loop

with
code:

quit


as for telling the user that the product is sold out, just have a few if statements in this part of the code
code:

        put "Which item(s) would you like to purchase? "
        put "a) Cathode Lights / Stock:", stock1, " / Price: $20"
        put "b) Computer Cases / Stock:", stock2, " / Price: $200"
        put "c) Fan Grills / Stock:", stock3, " / Price: $20"
        put "d) Lazer LED Lights / Stock:", stock4, " / Price: $30"
        put "e) Window Appliques / stock:", stock5, " / Price: $10"

to determine whether stock = 0 and if it is then instead of writing something like up there ^, put "item sold out" or whatever you want.
Tony




PostPosted: Wed May 26, 2004 8:28 am   Post subject: (No subject)

the problem with the code is that everything is hardcoded (including passwords, items and stock). It would be diffucult to add another item to the list since if statements and tables must be modified (and new variables created)

If you are familiar with arrays, you should defenatly try to run the program with a datafile to contain product listing and stock available.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
the_short1




PostPosted: Wed May 26, 2004 8:16 pm   Post subject: (No subject)

yea arrays would be better....


also i notice at top...

u have

var cart : int := 0
var tax :int := cart * .15


i would have that as


var tax : int := 0.15

because as it was.... cart was = 0 and .15 * 0 = 0 then ur tax will be nothing!!!


at the end of ur program..
use this:

cart := round (cart * .15) havng it this will add tax to the cart cost.. and round to nearest DOLAR....

having it cervants way will round .15 and that would be 0*cart... then ur cart will be NOTHING..
.





hope that clears things up!!..
Tony




PostPosted: Wed May 26, 2004 10:59 pm   Post subject: (No subject)

the_short1:
Quote:

var cart := 0

var tax:= cart *.15

notice the lack of :int? Razz

even though the tax is 0, it gets promoted to a real type variable because of that *. though it could have as easily be decleared as
code:

var tax := 0.0
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
the_short1




PostPosted: Thu May 27, 2004 7:01 am   Post subject: (No subject)

whoopz... i though i edited afta i posted and added them in...... guess not...

did u add for me... thx

either way the point was made..
AiR




PostPosted: Mon May 31, 2004 12:46 am   Post subject: (No subject)

Wow I really appreciate all your help on the tax guys, I finally got it working. I was afraid to post here before because I saw how some of you treat other newbies.

Heres an updated version. When I ask them if they want to select another item once they say "yes" it gets directly out of the loop and gives the user the price of the items without ever letting him pick another item.

Quote:
var password := 0214
var stock1, stock2, stock3, stock4, stock5 := 20
var answer, choice : string
var cart := 0
var quantity : int
var colr : int := 32
var money : int
var tax := .15
loop
loop
loop
colorback (white)
cls
color (black)
put " "
put "Please enter password."
color (white)
get password
color (black)
if password not= 0214 then
put " "
put "That is incorrect access is denied. "
elsif password = 0214 then
exit
end if
end loop

put " "
put "Welcome to Brightling, one of the world's top seller in computer modifications."
loop
put " "
put "Would you like to purchase an item(s) Yes [y] or No [n]?"
get answer
if answer = "No" or answer = "no" or answer = "N" or answer = "n" then
put "Good bye have a nice day."
loop
end loop
elsif answer = "yes" or answer = "Yes" or answer = "Y" or answer = "y" then
exit
end if
end loop

for a : -maxy .. maxy
if colr < 55 then
colr += 1
else
colr := 32
end if
drawarc (maxx div 2, a - 25, maxx div 2, maxy, 0, 180, black)
drawarc (maxx div 2, a, maxx div 2, maxy, 0, 180, colr)
delay (5)
end for
colorback (black)
cls
color (white)

put " "
put "Which item(s) would you like to purchase? "
put "a) Cathode Lights / Stock:", stock1, " / Price: $20"
put "b) Computer Cases / Stock:", stock2, " / Price: $200"
put "c) Fan Grills / Stock:", stock3, " / Price: $20"
put "d) Lazer LED Lights / Stock:", stock4, " / Price: $30"
put "e) Window Appliques / stock:", stock5, " / Price: $10"
loop
get choice
if choice not= "a" and choice not= "b" and choice not= "c" and choice not= "d" and choice not= "e" and choice not= "A" and choice not= "B" and choice not= "C" and choice not= "D" and
choice
not= "E" then
put "You have entered an invalid choice please choose an item"
put "from the list using a,b,c,d, or e."
% cathode lights
elsif choice = "a" or choice = "A" then
put "You have chosen Cathode lights which is 20 dollars for one."
put "How many would you like to buy?"
get quantity
if stock1 <= 0 then
stock1 := stock1 - 0
put "Out of Stock!"
else
stock1 := stock1 - quantity
cart := quantity * 20 + cart

put "Would you like to choose another item?"
get answer
if answer = "no" then
exit
elsif answer = "yes" then
put " "
end if
end if
%Computer Cases
elsif choice = "b" or choice = "B" then
put "You have chosen a Computer Case which is 200 dollars for one."
put "How many would you like to buy?"
get quantity
stock2 := stock2 - quantity
cart := quantity * 200 + cart
put "Would you like to choose another item?"
get answer
if answer = "no" then
exit
elsif answer = "yes" then
put " "
end if
%Fan grills
elsif choice = "c" or choice = "C" then
put "You have chosen a Fan Grill which is 20 dollars for one."
put "How many would you like to buy?"
get quantity
stock3 := stock3 - quantity
cart := quantity * 20 + cart
put "Would you like to choose another item?"
get answer
if answer = "no" then
exit
elsif answer = "yes" then
put " "
end if
elsif choice = "d" or choice = "D" then
put "You have chosen a Lazer LED Light which is 30 dollars for one."
put "How many would you like to buy?"
get quantity
stock4 := stock4 - quantity
cart := quantity * 30 + cart
put "Would you like to choose another item?"
get answer
if answer = "no" then
exit
elsif answer = "yes" then
put " "
end if
elsif choice = "e" or choice = "E" then
put "You have chosen a Window Applique which is 10 dollars for one."
put "How many would you like to buy?"
get quantity
stock5 := stock5 - quantity
cart := quantity * 10 + cart
put "Would you like to choose another item?"
get answer
if answer = "no" then
exit
elsif answer = "yes" then
put " "
end if
end if
exit
end loop
put "The total amount you have to pay is ", cart * .15 + cart, " dollars"
put "Would you like to pay with cheque, cash, or credit card."
get choice
if choice = "cash" then
put "How much will you be paying?"
get money
cart := cart + round (cart * 0.15)
put "Your total change will be ", money - cart
delay (1000)
cart := cart * 0
end if
end loop

end loop
Tony




PostPosted: Mon May 31, 2004 1:02 am   Post subject: (No subject)

AiR wrote:
I saw how some of you treat other newbies.


haha, some newbs get it harsh when they post asking something along the lines of "i can't make (something complex that is most likely a project), give me code" and they post such in a wrong forum too Rolling Eyes

you on other hand had most of the program done and knew exactly what you had problems with Smile we're always glad to have members such as you AiR and I hope you'll enjoy your stay @ compsci Very Happy
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: