Coding
Author |
Message |
jayshaw94
|
Posted: Wed Apr 20, 2011 8:42 am Post subject: Coding |
|
|
Hello compsci
3 Questions.
1) There are 4 options for one answer. 0,0.5,1,2. The user must choose one of those options if not an error will be shown and the program will then loop back. My question is how would I code that? I tried the 'or' option with no luck (if op1 not = 0 or 0.5 or 1 or 2 then put "error")
2) I have a bunch of procedures. The procedures are called at the end of the program. My program calculates height/width based on certain things. Each procedure will show the calucations for the height and frame. I would then like to put/show those calculations at the end of the program again.
Example: Once the program has finished the bottom will state the height/width/etc for everything. How would I do that. Here is my coding so far. Any help would be great. Thank you guys!
3) Why is it that the put statement will not excute after calling the procedures?
var da, choice1, choice2, nojp, nosp, nocw, nocjp, nocsp, h1, h2, h3, w1, w2, w3, choice, HOF1, HOF2, WOF1, howi, wowi, hogi, wogi, howi1, wowi1, hogi1, wogi1 : int
var afw1, afw2a, afw2b, afw3, afw4a, afw4b, afw5, op1, op2, op3, op4, op5, od, TTLI : real
var RailA := 46
var RailB := 41
procedure Form1
HOF1 := (h1) - (RailA) %Height of frame based on RailA= Lowest Room Height substract 46%
HOF2 := (h1) - (RailB) %Height of frame based on RailB= Lowest Room Height substract 41%
howi := (HOF1) - (58) %Height of wooden infill based on RailA= height of frame based on RailA substract 58%
wowi := (w1) - (23) %Width of wooden infill based on RailA= lowest room width substract 23%
hogi := (HOF1) - (60) %Height of glass infill based on RAilA= heigh of frame based on RailA substract 60%
wogi := (w1) - (20) %Width of glass infill based on RailA= lowest room width substract 20%
howi1 := (HOF2) - (58) %Height of wooden infill based on RailB= Height of Frame based on RailB substract 58%
wowi1 := (w1) - 23 %Width of wooden infill based on RailB= lowest room width substract 23
hogi1 := (HOF2) - (60) %Height of glss infill based on RailB= Height of Frame base on RailB substract 60
wogi1 := (w1) - (23) %Width of glass infill based on RailB= lowest room width substract 23
if choice = 1 then
put "Height of frame: ", HOF1, " Width of Frame: ", w1, " The Height of the wooden infill is: ", howi, " The Width of the wooden infill is: ", wowi
%Outputs height and width of frame as well as wooden infill based on RailA%
elsif choice = 2 then
put "Height of frame: ", HOF1, " Width of Frame: ", w1, " The Height of the glass infill is: ", hogi, " The Width of the glass infill is: ", wogi
%Outputs height and width of frame as well as glass infill based on RailA%
elsif choice = 3 then
put "Height of Frame: ", HOF2, " Width of Frame: ", w1, " The Height of the wooden infill is: ", howi1, " The Width of the wooden infill is: ", wowi1
%Outputs height and width of frame as well as wooden infill based on RailB%
elsif choice = 4 then
put "Height of Frame: ", HOF2, " Width of Frame: ", w1, " The Height of the glass infill is: ", howi1, " The Width of the wooden infill is: ", wowi1
%Outputs height and width of frame as well as glass infill based on RailB%
end if
end Form1
procedure RailChoice %Option for rail et on the floor or set into floor as well as infill type%
put "Rail A (1)Set on the Floor with Wooden infill"
put "Rail A (2)Set on the Floor with Glass infill"
put "Rail B (3)Set into the Floor with Wooden infill"
put "Rail B (4)Set into the Floor with Glass infill"
get choice
loop
if choice > 4 then
put "Error please try again" %If user picks an option greater than 4 error is given%
RailChoice
end if
exit when choice <= 4
end loop
end RailChoice
procedure hwconfig
put "Enter lowest room height" %User enters required information%
get h1
put "Enter second lowest room height"
get h2
put "Enter third lowest room height"
get h3
put "Enter lowest room width"
get w1
put "Enter second lowest room width"
get w2
put "Enter third lowest room widht"
get w3
if (h1) - (h2) > 12 then
put "Exceeds 12mm limit Rail B is the default" %If any of the two heights that are substracted are greather than 12 this error message is given%
elsif (h2) - (h3) > 12 then
put "Exceeds 12mm limit Rail B is the default"
elsif (h3) - (h1) > 12 then
put "Exceeds 12mm limit Rail B is the default"
elsif (h1) - (h3) > 12 then
put "Exceeds 12mm limit Rail B is the default"
end if
end hwconfig
procedure OpeningDeductions
put "Enter the number of Jumbo post(s) required"
get nojp
put "Enter either 0, 0.5, 1, or 2"
get op1
TTLI := (w1) - (100) * (op1) + (2)
put "Enter the number of Small post(s) required"
get nosp
put "Enter either 0, 0.5, 1, or 2"
get op2
put "Enter the number of connection(s) to wall"
get nocw
put "Enter either 0, 1, or 2"
get op3
put "Enter the number of connection(s) to Jumbo Post"
get nocjp
put "Enter either 0, 1, or 2"
get op4
put "Enter the number of connection(s) to Small Post"
get nocsp
put "Enter either 0 or 1"
get op5
od := (100) * (nojp) + (op1) + (44) * (nosp) + (op2) + (36) * (nocw) + (op3) + (36) * (nocjp) + (op4) + (36) * (nocsp) + (op5)
put "Opening Deductions: ", od, "MM"
put "Top Track Length inside the opening: ", TTLI, "MM"
end OpeningDeductions
procedure D_A
put "Number of door(s) to be used"
get da
if da = 1
then
put "1 Option:"
put "1) Type of Track: Single Number of Rubber Seals 1 Number of Overlaps:0"
afw1 := (w1 - 6) * (1) + (19) - (od)
put "Actual Frame Width: ", afw1
elsif da = 2
then
put "2 Options:"
put "1) Type of Track: Single Number of Rubber Seals:1 Number of Overlaps:0"
put "2) Type of Track: Double Number of Rubber Seals:2 Number of Rubber Seals:1"
put "Enter option 1 or 2"
get choice1
if choice1 = 1 then
afw2a := (w1 - 6) * (1) + (19) - (od)
put "Actual Frame Width: ", afw2a
elsif choice1 = 2 then
afw2b := (w1 - 6) * (2) + (19) * (1) - (od)
put "Actual Frame Width: ", afw2b
else
D_A
end if
elsif da = 3
then
put "2 Options:"
put "1) Type of Track: Double Number of Rubber Seals:2 Number of Overlaps:2"
put "2) Type of Track: Triple Number of Rubber Seals:2 Number of Overlaps:2"
afw3 := (w1 - 6) * (2) + (19) * (2) - (od)
put "Actual Frame Width: ", afw3
elsif da = 4
then
put "2 Options:"
put "1) Type of Track: Double Number of Rubber Seals:2 Number of Overlaps:3"
put "2) Type of Track: Double Number of Rubber Seals:3 Number of Overlaps:2"
put "Enter option 1 or 2"
get choice2
if choice2 = 1 then
afw4a := (w1 - 6) * (2) + (19) * (3) - (od)
put "Actual Frame Width: ", afw4a
elsif choice2 = 2 then
afw4b := (w1 - 6) * (3) + (19) * (2) - (od)
put "Actual Frame Width: ", afw4b
else
D_A
end if
elsif da = 5
then
put "1 Option:"
put "1) Type of Track: Double Number of Rubber Seals:2 Number of Overlaps:4"
afw5 := (w1 - 6) * (2) + (19) * (4) - (od)
put "Actual Frame Width: ", afw5
end if
loop
if da > 5
then
put "Error door limit has been exceeded please try again"
D_A
exit when da <= 5
end if
end loop
end D_A
RailChoice
hwconfig
Form1
OpeningDeductions
D_A |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Insectoid
|
Posted: Wed Apr 20, 2011 9:03 am Post subject: RE:Coding |
|
|
1. Try "if op1 not= 0 or op1 not= 0.5 or op1 not= 1 or nop1 not= 2"
2.
code: | get choice
loop
if choice > 4 then
put "Error please try again" %If user picks an option greater than 4 error is given%
RailChoice
end if
exit when choice <= 4
end loop |
I doubt you've looked at recursion, which is what you're doing here. This procedure never exists, which is why your output at the end of the program doesn't work. I'm actually not sure if this compiles...
Also,
code: | var da, choice1, choice2, nojp, nosp, nocw, nocjp, nocsp, h1, h2, h3, w1, w2, w3, choice, HOF1, HOF2, WOF1, howi, wowi, hogi, wogi, howi1, wowi1, hogi1, wogi1 : int
var afw1, afw2a, afw2b, afw3, afw4a, afw4b, afw5, op1, op2, op3, op4, op5, od, TTLI : real |
This makes my eyes bleed. Use arrays!
code: | var h : array 1..3 of int
var 2 : array 1..3 of int
var afw : array 1..7 of real
var op : array 1..5 of real |
Your variable names are terribly by the way. I should understand what 'HOF1' is just by reading it. |
|
|
|
|
|
jayshaw94
|
Posted: Wed Apr 20, 2011 9:36 am Post subject: Re: Coding |
|
|
Thank you Insectoid.
Yeah my coding is very messy. The program does compile still needs some tuning (loops and what not)
What do you mean by recursion?
You're right about the variables and understanding what they are I guess I would have to make it more user friendly
Thanks again for your help |
|
|
|
|
|
Insectoid
|
Posted: Wed Apr 20, 2011 10:38 am Post subject: RE:Coding |
|
|
Look at procedure Railchoice. Inside it, you call Railchoice. The function is calling itself. That is recursion. |
|
|
|
|
|
jayshaw94
|
Posted: Wed Apr 20, 2011 12:28 pm Post subject: Re: Coding |
|
|
Yeah I wasnt sure how else to do that procedure or other ones. If the person went over the limit i wanted that procedure to come back again. It works but I know there is a better way which I dont know of.
Thank you for the quick replies |
|
|
|
|
|
Insectoid
|
Posted: Wed Apr 20, 2011 12:45 pm Post subject: RE:Coding |
|
|
You don't need that line at all. It should be fine, since it's a loop. Just put that 'get choice' inside the loop. |
|
|
|
|
|
jayshaw94
|
Posted: Wed Apr 20, 2011 1:58 pm Post subject: Re: Coding |
|
|
thank you! worked great insectoid |
|
|
|
|
|
|
|