looping possibility?
Author |
Message |
moneywin
|
Posted: 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 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Beastinonyou
|
Posted: 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!
Turing: | var destination, answer, qualityt : string
var total : int := 0
put "Where would you Like to Travel to? ", "Type '1' for Hawaii."
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 += 600
elsif qualityt = "Economy" or qualityt = "economy" then
total += 400
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 += 300
elsif qualityt = "Economy" or qualityt = "economy" then
total += 200
end if
end if
end if
put skip
put "You have decided to go to ", destination, ", the price of your travel is: $", total |
|
|
|
|
|
|
Aange10
|
Posted: Fri Nov 11, 2011 10:03 pm Post subject: RE:looping possibility? |
|
|
I have decided to go to 1 the price of my travel is: $600
(: I always wanted to visit 1 |
|
|
|
|
|
moneywin
|
Posted: 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? |
|
|
|
|
|
moneywin
|
Posted: 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 |
|
|
|
|
|
Beastinonyou
|
Posted: 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 :
Turing: | total := total + 300 |
The "+=" combination means to increment whatever value on the right, to whatever value on the left. |
|
|
|
|
|
moneywin
|
Posted: 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 |
|
|
|
|
|
moneywin
|
Posted: 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. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Aange10
|
Posted: 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:
Turing: |
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
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
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
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
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
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
put skip
put "You have decided to go to place", destination, ", the price of your travel is: $", total
|
Do you see what you did wrong? |
|
|
|
|
|
Beastinonyou
|
Posted: 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:
Turing: | var answer, qualityt : string
var people, total, destination : int := 0
var trainFC : array 1 .. 6 of int := init (600, 780, 900, 1200, 780, 900)
var trainE : array 1 .. 6 of int := init (400, 450, 600, 1000, 600, 400)
var airplaneFC : array 1 .. 6 of int := init (300, 500, 800, 1300, 1000, 500)
var airplaneE : array 1 .. 6 of int := init (200, 600, 1000, 1200, 800, 600)
procedure allInOne (destination_ : int, answer_, qualityt_ : string)
if qualityt_ = "First Class" or qualityt_ = "first class" then
if answer_ = "Airplane" or answer_ = "airplane" then
total += airplaneFC (destination_)
elsif answer_ = "Train" or answer_ = "train" then
total += trainFC (destination_)
end if
elsif qualityt_ = "Economy" or qualityt_ = "economy" then
if answer_ = "Airplane" or answer_ = "airplane" then
total += airplaneE (destination_)
elsif answer_ = "Train" or answer_ = "train" then
total += trainE (destination_)
end if
end if
end allInOne
put "How many people are coming? " ..
get people
put ""
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"
put "Where would you like to go? " ..
get destination
put ""
put "What would you like to travel by? " ..
get answer
put ""
put "First Class or Economy? " ..
get qualityt : *
put ""
allInOne (destination, answer, qualityt)
put "Your Total Estimate is: $", total * people
|
OR:
Turing: | var answer, qualityt : string
var people, total, destination : int := 0
var trainFC : array 1 .. 6 of int := init (600, 780, 900, 1200, 780, 900)
var trainE : array 1 .. 6 of int := init (400, 450, 600, 1000, 600, 400)
var airplaneFC : array 1 .. 6 of int := init (300, 500, 800, 1300, 1000, 500)
var airplaneE : array 1 .. 6 of int := init (200, 600, 1000, 1200, 800, 600)
function allInOne (destination_ : int, answer_, qualityt_ : string) : int
if qualityt_ = "First Class" or qualityt_ = "first class" then
if answer_ = "Airplane" or answer_ = "airplane" then
result airplaneFC (destination_)
elsif answer_ = "Train" or answer_ = "train" then
result trainFC (destination_)
end if
elsif qualityt_ = "Economy" or qualityt_ = "economy" then
if answer_ = "Airplane" or answer_ = "airplane" then
result airplaneE (destination_)
elsif answer_ = "Train" or answer_ = "train" then
result trainE (destination_)
end if
end if
end allInOne
put "How many people are coming? " ..
get people
put ""
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"
put "Where would you like to go? " ..
get destination
put ""
put "What would you like to travel by? " ..
get answer
put ""
put "First Class or Economy? " ..
get qualityt : *
put ""
total := allInOne (destination, answer, qualityt)
put "Your Total Estimate is: $", total * people
|
|
|
|
|
|
|
Velocity
|
Posted: 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 |
|
|
|
|
|
Beastinonyou
|
Posted: 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. |
|
|
|
|
|
Zren
|
Posted: Thu Nov 17, 2011 11:16 am Post subject: RE:looping possibility? |
|
|
Turing: |
if answer_ = "Airplane" or answer_ = "airplane" then
|
Ew.
Basically you compare strings insensitive to their case. |
|
|
|
|
|
Beastinonyou
|
Posted: 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 |
|
|
|
|
|
Aange10
|
Posted: 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(: |
|
|
|
|
|
|
|