Computer Science Canada looping possibility? |
Author: | moneywin [ Fri Nov 11, 2011 6:03 pm ] |
Post subject: | looping possibility? |
can anyone tell me why my total cant be outputted in this program? THANKS . and is it possible to have a if statemnet inside of a if statement in another if statement ? My Problem : var destination, answer, qualityt, qualitytt : string var total : int total := 0 put " These are the choices" 1. Hawaii get destaination if destination = 1 then put "would you like to play by airplane or train?" get answer if answer = train then put " First Class or Economy" get qualityt if answer = "First Class" then total := total+600 elsif answer = "Economy" then total := total + 400 end if elsif answer = "airplane" then put "First Class or Economy" end if get qualitytt if answer = "First Class "then total := total +300 end if elsif answer = "Economy" then total := total +200 end if put "you have deceided to go to", destination, " the price of your travel is", total |
Author: | Beastinonyou [ Fri Nov 11, 2011 8:22 pm ] | ||
Post subject: | Re: looping possibility? | ||
moneywin @ Fri Nov 11, 2011 6:03 pm wrote: is it possible to have a if *statement* inside of a if statement in another if statement ? The answer is Yes, any statement within itself would be referred to as Nested. A Nested If structure is composed of multiple if statements inside of each other Note: I HIGHLY advise pasting your code into One Turing window, and My code into another, and Compare!
|
Author: | Aange10 [ Fri Nov 11, 2011 10:03 pm ] |
Post subject: | RE:looping possibility? |
![]() (: I always wanted to visit 1 |
Author: | moneywin [ Sat Nov 12, 2011 8:10 am ] |
Post subject: | RE:looping possibility? |
I wanna thank you first of all, and secondo fl all what does get qualityt: * represent? |
Author: | moneywin [ Sat Nov 12, 2011 8:13 am ] |
Post subject: | RE:looping possibility? |
Also do yo u knwo how come? total +=300 ^what does it mean? i thought it was total := total +300 ^ but when i tried this it doesnt work :/ im sorry for these questions, i just wana learn from my mistake. and thanks |
Author: | Beastinonyou [ Sat Nov 12, 2011 8:44 am ] | ||||||
Post subject: | Re: looping possibility? | ||||||
when you need the user to enter a string, It returns all the characters, but if they're entering Two or more words containing a space, it only returns the word up until the space.
what the colon + asterisk does is ensures that the computer receives everything the user types, until the Enter key is hit. I noticed that when I fixed your program, only Economy worked, because when you would type "First Class", the computer gets the word "First", but nothing after because of the space. This was preventing adding the total. As for
That is the exact same as :
The "+=" combination means to increment whatever value on the right, to whatever value on the left. |
Author: | moneywin [ Sat Nov 12, 2011 10:24 pm ] |
Post subject: | RE:looping possibility? |
if i wish to do more than one place , why doesnt it work, i used your format as an example: but im really curous to why it cnat due more than one desintation, like i tried running it , and the places always end up being $0 For examples ; i typed in " 2 " and it would skip all the process, and its hte same problem when i type in 3,4,5,6. var destination, answer, qualityt : string var total, people : int total:= 0 put "How many people are going" get people put "Where would you Like to Travel to? " put "Type '1' for Hawaii." put "Type '2' for California" put "Type '3' for Hollywood" put "Type '4' for South Pole" put "Type '5' for North Pole" put "Type '6' for Artic" get destination put skip if destination = '1' then put "Would you like to Travel by Airplane, or Train? " .. get answer if answer = "Train" or answer = "train" then put skip put "Would you like to travel in First Class, or Economy? " get qualityt : * if qualityt = "First Class" or qualityt = "first class" then total := total + 600 *people elsif qualityt = "Economy" or qualityt = "economy" then total := total + 400 *people end if elsif answer = "Airplane" or answer = "airplane" then put skip put "Would you Fly in First Class, or Economy? " get qualityt : * if qualityt = "First Class" or qualityt = "first class" then total := total + 300 *people elsif qualityt = "Economy" or qualityt = "economy" then total := total + 200* people end if end if if destination = '2' then put "Would you like to Travel by Airplane, or Train? " .. get answer if answer = "Train" or answer = "train" then put skip put "Would you like to travel in First Class, or Economy? " get qualityt : * if qualityt = "First Class" or qualityt = "first class" then total += 780 *people elsif qualityt = "Economy" or qualityt = "economy" then total += 450 *people end if elsif answer = "Airplane" or answer = "airplane" then put skip put "Would you Fly in First Class, or Economy? " get qualityt : * if qualityt = "First Class" or qualityt = "first class" then total += 500 *people elsif qualityt = "Economy" or qualityt = "economy" then total += 600* people end if end if if destination = '3' then put "Would you like to Travel by Airplane, or Train? " .. get answer if answer = "Train" or answer = "train" then put skip put "Would you like to travel in First Class, or Economy? " get qualityt : * if qualityt = "First Class" or qualityt = "first class" then total += 900 *people elsif qualityt = "Economy" or qualityt = "economy" then total += 600 *people end if elsif answer = "Airplane" or answer = "airplane" then put skip put "Would you Fly in First Class, or Economy? " get qualityt : * if qualityt = "First Class" or qualityt = "first class" then total += 800 *people elsif qualityt = "Economy" or qualityt = "economy" then total += 1000* people end if end if if destination = '4' then put "Would you like to Travel by Airplane, or Train? " .. get answer if answer = "Train" or answer = "train" then put skip put "Would you like to travel in First Class, or Economy? " get qualityt : * if qualityt = "First Class" or qualityt = "first class" then total += 1200 *people elsif qualityt = "Economy" or qualityt = "economy" then total += 1000 *people end if elsif answer = "Airplane" or answer = "airplane" then put skip put "Would you Fly in First Class, or Economy? " get qualityt : * if qualityt = "First Class" or qualityt = "first class" then total += 1300 *people elsif qualityt = "Economy" or qualityt = "economy" then total += 1200* people end if end if if destination = '5' then put "Would you like to Travel by Airplane, or Train? " .. get answer if answer = "Train" or answer = "train" then put skip put "Would you like to travel in First Class, or Economy? " get qualityt : * if qualityt = "First Class" or qualityt = "first class" then total += 780 *people elsif qualityt = "Economy" or qualityt = "economy" then total += 600 *people end if elsif answer = "Airplane" or answer = "airplane" then put skip put "Would you Fly in First Class, or Economy? " get qualityt : * if qualityt = "First Class" or qualityt = "first class" then total += 1000 *people elsif qualityt = "Economy" or qualityt = "economy" then total += 800* people end if end if if destination = '6' then put "Would you like to Travel by Airplane, or Train? " .. get answer if answer = "Train" or answer = "train" then put skip put "Would you like to travel in First Class, or Economy? " get qualityt : * if qualityt = "First Class" or qualityt = "first class" then total += 900 *people elsif qualityt = "Economy" or qualityt = "economy" then total += 400 *people end if elsif answer = "Airplane" or answer = "airplane" then put skip put "Would you Fly in First Class, or Economy? " get qualityt : * if qualityt = "First Class" or qualityt = "first class" then total += 500 *people elsif qualityt = "Economy" or qualityt = "economy" then total += 600* people end if end if end if end if end if end if end if end if put skip put "You have decided to go to place", destination, ", the price of your travel is: $", total |
Author: | moneywin [ Sat Nov 12, 2011 10:27 pm ] |
Post subject: | RE:looping possibility? |
and with great gratidue , for all your help. You have taught me how to do turing, i have a much better understanding now. Thanks. ![]() |
Author: | Aange10 [ Sun Nov 13, 2011 12:24 am ] | ||
Post subject: | RE:looping possibility? | ||
Well, your problem is you can't just stick end if at the bottom of the program and call it good. You have to end the ifs when their condition stops applying, not at the bottom. All of you're destinations work, except for the fact that you never end the conditions determining which place you chose to go. A quick fix:
Do you see what you did wrong? |
Author: | Beastinonyou [ Sun Nov 13, 2011 1:33 pm ] | ||||
Post subject: | Re: looping possibility? | ||||
I can't stand to look at all that unnecessary coding. I advise you take a look at this:
OR:
|
Author: | Velocity [ Wed Nov 16, 2011 9:44 pm ] |
Post subject: | RE:looping possibility? |
@beast Your nice... the poor chap probably doesnt even understand half the stuff you did there. Nice way to make someone feel bad :S |
Author: | Beastinonyou [ Wed Nov 16, 2011 11:05 pm ] |
Post subject: | Re: RE:looping possibility? |
Velocity @ Wed Nov 16, 2011 9:44 pm wrote: @beast
Your nice... the poor chap probably doesnt even understand half the stuff you did there. Nice way to make someone feel bad :S Well, everybody goes through that.. When somebody on the forums solves your problem, you look at it and go, "damn, why didn't I think of that", or "Wow, I didn't realize that could be done in that way." Now, they can learn to work with them, and they'll get better with them. The more practice you get with a concept, the more familiar you are with using it. When you started your first month in programming in Turing, did you go over Procedures and Functions? Not likely, most teachers are just teaching you repetitive structures, and graphics. Realistically, It was more like Constructive Criticism. |
Author: | Zren [ Thu Nov 17, 2011 11:16 am ] | ||||
Post subject: | RE:looping possibility? | ||||
Ew.
Basically you compare strings insensitive to their case. |
Author: | Beastinonyou [ Thu Nov 17, 2011 3:36 pm ] | ||
Post subject: | Re: RE:looping possibility? | ||
Zren @ Thu Nov 17, 2011 11:16 am wrote:
Basically you compare strings insensitive to their case. Could've done that, but procedures / functions would have been enough of a change in his program. Str.Lower and Str.Upper is mainly just for convenience |
Author: | Aange10 [ Thu Nov 17, 2011 5:28 pm ] |
Post subject: | Re: RE:looping possibility? |
Beastinonyou @ 16/11/2011, 10:05 pm wrote: ...When you started your first month in programming in Turing, did you go over Procedures and Functions? Not likely, most teachers are just teaching you repetitive structures, and graphics... I started my first month two months ago. Concept takes a while to learn. Problem-solving takes a while to figure out. Syntax is given for a language. I learned procedures the same day I learned put (Functions confused me because of the typespecs). It should not be hard to learn (especially such easy) syntax. Turing Walkthrough has 95% of everything in it. Google is free for everybody with internet to use. Sorry for going OT(: |