Code Comments
Programming Forum and web based access to our favorite programming groups.Does anyone know how to create a program in COBOL using the following promts (as it would be written in MS Excel)? =IF(A2>89,"A",IF(A2>79,"B", IF(A2>69,"C",IF(A2>59,"D","F")))) Thanks, Kris
Post Follow-up to this messageOn 6 Feb 2007 11:49:21 -0800, "selworthy" <kristopher.crockett@charter.net> wrote: >Does anyone know how to create a program in COBOL using the following >promts (as it would be written in MS Excel)? > >=IF(A2>89,"A",IF(A2>79,"B", IF(A2>69,"C",IF(A2>59,"D","F")))) Yes. Any CoBOL programmer should be able to do this, are you hiring?
Post Follow-up to this messageselworthy wrote: > Does anyone know how to create a program in COBOL using the following > promts (as it would be written in MS Excel)? > > =IF(A2>89,"A",IF(A2>79,"B", IF(A2>69,"C",IF(A2>59,"D","F")))) > > (Waves hand) I do! I do!
Post Follow-up to this messageselworthy wrote: > Does anyone know how to create a program in COBOL using the following > promts (as it would be written in MS Excel)? > > =IF(A2>89,"A",IF(A2>79,"B", IF(A2>69,"C",IF(A2>59,"D","F")))) I have an idea how I'd do it - what have you tried? -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~ ~ / \ / ~ Live from Montgomery, AL! ~ ~ / \/ o ~ ~ ~ / /\ - | ~ daniel@thebelowdomain ~ ~ _____ / \ | ~ http://www.djs-consulting.com ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ GEEKCODE 3.12 GCS/IT d s-:+ a C++ L++ E--- W++ N++ o? K- w$ ~ ~ !O M-- V PS+ PE++ Y? !PGP t+ 5? X+ R* tv b+ DI++ D+ G- e ~ ~ h---- r+++ z++++ ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~ "Who is more irrational? A man who believes in a God he doesn't see, or a man who's offended by a God he doesn't believe in?" - Brad Stine
Post Follow-up to this messageLX-i wrote: > selworthy wrote: > > I have an idea how I'd do it - what have you tried? Here's what I tried... identification division. program-id. GradeMachine. data division. working-storage section. 77 inputGrade pic 9(03). 77 outputGrade pic X(01). procedure division. display "Please enter the grade" accept inputGrade call "AssignGradeLetter" using inputGrade, outputGrade end-call display "The grade is " outputGrade stop run
Post Follow-up to this messageOn Feb 6, 10:30 pm, LX-i <lxi0...@netscape.net> wrote: > LX-i wrote: > > > > Here's what I tried... > > identification division. > program-id. GradeMachine. > > data division. > working-storage section. > > 77 inputGrade pic 9(03). > 77 outputGrade pic X(01). > > procedure division. > > display "Please enter the grade" > accept inputGrade > > call "AssignGradeLetter" > using inputGrade, outputGrade > end-call > > display "The grade is " outputGrade > > stop run > . > > identification division. > program-id. AssignGradeLetter. > > data division. > working-storage section. > > 01 grades. > 12 pic X value "F". [snip look up table] > 12 pic X value "A". > 01 gradeTable redefines grades. > 12 letterGrade occurs 100 times > indexed by letterGradeIdx > pic X(01). > > linkage section. > 77 inputGrade pic 9(03). > 77 outputGrade pic X(01). > > procedure division > using inputGrade outputGrade. > > evaluate inputGrade when 1 thru 100 > set letterGradeIdx to inputGrade > move letterGrade (letterGradeIdx) to outputGrade > when other > move "?" to outputGrade > end-evaluate > . > end program AssignGradeLetter. > > end program GradeMachine. Looking at the equal widths of most of the class intervals, why not use linear interpolation instead? <rhetorical question> identification division. program-id. grade. environment division. configuration section. source-computer. ibm-pc. object-computer. ibm-pc. data division. working-storage section. 01 in-num pic 9(3). 01 out-grade pic x. 01 grade-idx pic s9. 01 grades. 05 filler pic x(5) value 'FDCBA'. 01 grade-table redefines grades. 05 letter-grade pic x occurs 5 times. procedure division. main. display 'enter numeric grade' accept in-num perform num-to-grade display 'grade is ' out-grade stop run
Post Follow-up to this message
"selworthy" <kristopher.crockett@charter.net> schreef in bericht
news:1170791361.599169.251290@j27g2000cwj.googlegroups.com...
> Does anyone know how to create a program in COBOL using the following
> promts (as it would be written in MS Excel)?
>
> =IF(A2>89,"A",IF(A2>79,"B", IF(A2>69,"C",IF(A2>59,"D","F"))))
>
>
> Thanks,
> Kris
>
Evaluate true
when A2 > 89
Move 'A' to {field}
when A2 > 79
Move 'B' to {field}
when A2 > 69
Move 'C' to {field}
when A2 > 59
Move 'D' to {field}
when other
Move 'F' to {field}
end-evaluate.
Persume A2 is a numeric field.
And {field} is an alfanumeric field.
Post Follow-up to this message
"selworthy" <kristopher.crockett@charter.net> wrote in message
news:1170791361.599169.251290@j27g2000cwj.googlegroups.com...
> Does anyone know how to create a program in COBOL using the following
> promts (as it would be written in MS Excel)?
>
> =IF(A2>89,"A",IF(A2>79,"B", IF(A2>69,"C",IF(A2>59,"D","F"))))
>
>
> Thanks,
> Kris
>
Perfect text book example of a decision tree, and can be implemented nicely
with a single COBOL nested IF.
if A2 > 59
if A2 > 69
if A2 > 79
if A2 > 89
move "A" to grade
else
move "B" to grade
end-if
else
move "C" to grade
end-if
else
move "D" to grade
end-if
else
move "F" to grade
end-if
This approach can be easily amended if the "intervals" or grades change,
doesn't use a contrived EVALUATE TRUE (which serves no purpose other than to
document the ranges), and is efficient at execution time. (If this is
actually a consideration, you can make it REALLY efficient, by reorganising
it so that the most likely conditions are tested first, but that means
introducing NOT and makes the whole thng much less elegant. Simple is
good...:-))
Of course, it is banned on most sites because ...
a. People misuse it (mainly by nesting further conditions into the false
branches, which adulterates the purity and simplicity of the construct)
b. COBOL "programmers" are not expected to understand "logic" and it is
therefore too complex for them.
c. Managers should be able to read COBOL programs and this sort of thing
smacks of "tech" and doesn't look like English, so it must therefore be
stamped out at once.
(Yes, I'm cynical... having worked as a programmer on one or two COBOL
sites, for one or two years, in one or two countries, and seen the power of
COBOL dragged down to the lowest common denominator by people who have no
idea what computer programming is about... :-))
I can't take credit for this (not that I suspect any will be forthcoming
anyway... :-)). I learned it in 1968 (and modified it slightly to
accommodate scope delimiters when they became available) from a book ("COBOL
logic and Programming",
ly, long since out of print) published by the
University of Louisiana, and written by Doctor Fritz D. MacCameron (whom I
suspect is also now "out of print"... pity... As a very young, keen, COBOL
programmer I devoured his book avidly and I still think it was one of the
best books ever written about COBOL.
Pete.
Post Follow-up to this messageOn Feb 7, 8:49 am, "selworthy" <kristopher.crock...@charter.net> wrote: > Does anyone know how to create a program in COBOL using the following > promts (as it would be written in MS Excel)? > > =IF(A2>89,"A",IF(A2>79,"B", IF(A2>69,"C",IF(A2>59,"D","F")))) I much prefer table driven code rather than programmer driven code. With this code the table can be changed to give different grades without changing the program logic. It can even add additional grades (such as 'E') with changing the logic of the code. I would actually have the program read the scores and grades from a configuration file or a SQL table and then it could be changed by the users without having to change the code at all or even recompile. In fact one could have as a run parameter the name of the set of scores and grades to be used, or have this as an item in a file of results that need grading such that the program will select the appropriate set itself. Just make sure that each set ends with a 999 entry. 01 Score PIC 9(3). 01 Grade PIC X. 01 Grade -Table. 03 FILLER PIC X(4) VALUE "000F". 03 FILLER PIC X(4) VALUE "060D". 03 FILLER PIC X(4) VALUE "070C". 03 FILLER PIC X(4) VALUE "080B". 03 FILLER PIC X(4) VALUE "090A". 03 FILLER PIC X(4) VALUE "999-". 01 Grade-Items REDEFINES Grade-Table. 03 Grade-Item OCCURS 6. 05 Grade-Score PIC 999. 05 Grade-Result PIC X. DISPLAY "Enter Score:" ACCEPT Scrore PERFORM VARYING I FROM 1 BY 1 UNTIL Grade-Result(I) > 100 IF ( Score >= Grade-Score(I) ) MOVE Grade-Result(I) TO Grade END-IF END-PERFORM DISPLAY "Grade: " Grade
Post Follow-up to this messageOn Feb 8, 6:34 pm, "Pete Dashwood" <dashw...@removethis.enternet.co.nz> wrote: > "selworthy" <kristopher.crock...@charter.net> wrote in message > > news:1170791361.599169.251290@j27g2000cwj.googlegroups.com...> Does anyone know how to create a program in COBOL using the following > > > > Perfect text book example of a decision tree, and can be implemented nicel y > with a single COBOL nested IF. > > if A2 > 59 > if A2 > 69 > if A2 > 79 > if A2 > 89 > move "A" to grade > else > move "B" to grade > end-if > else > move "C" to grade > end-if > else > move "D" to grade > end-if > else > move "F" to grade > end-if > > This approach can be easily amended if the "intervals" or grades change, > doesn't use a contrived EVALUATE TRUE (which serves no purpose other than to > document the ranges), and is efficient at execution time. (If this is > actually a consideration, you can make it REALLY efficient, by reorganisin g > it so that the most likely conditions are tested first, but that means > introducing NOT and makes the whole thng much less elegant. Simple is > good...:-)) > Or, if you like Pascal you can structure the nested IF as if A2 > 100 move "?" to grade else if A2 > 89 move "A" to grade else if A2 > 79 move "B" to grade else if A2 > 69 move "C" to grade else if A2 > 59 move "D" to grade else move "F" to grade end-if end-if end-if end-if end-if but why not let the compiler do the work and use evaluate A2 when 0 through 59 move "F" to grade when 60 through 69 move "D" to grade when 70 through 79 move "C" to grade when 80 through 89 move "B" to grade when 90 through 100 move "A" to grade when other move "?" to grade end-evaluate instead? -- Elliot aside: My code example using interpolation was meant as a joke.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.