#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Location
    Platteville, WI
    Posts
    23
    Rep Power
    0

    First cobol program (gpa calculator)


    just started Cobol this semester and need some help with my first program. When I go to run it doesn't fully run my first paragraph. It doesnt' prompt me for a response 'yes/no'

    any ideas on what to do? also some help with structure and other tips would be great as it's hard to understand my teacher.

    Code:
    ******************************************************************
          * This program determines the semester GPA and the cumlative GPA
          * of the student.  The user inputs their student number, then
          * asks for info about one course which is the course number,
          * credits, and grade.
          *                                                                *
          ******************************************************************
          *
           Environment Division.
          *
           Data Division.
          *
           Working-Storage Section.
          *
           01 WS-Student-Data.
          *
               05 WF-Student-Number        pic 9(5).
               05 WF-Course-Number         pic 9(6).
               05 WF-Credit-Hours          pic 9.
               05 WF-Grade                 pic 99.
    
           01 WS-Switches.
               05 WD-Response              pic x(3).
               05 WD-New-Student           pic x(3).
    
           01 WS-Total.
               05 WT-Student-Count         pic 9(3).
               05 WT-Cumlative             pic 99v999.
               05 WT-Credits               pic 99.
               05 WT-Total-Grade           pic 99.
               05 WT-All-Students-GPA      pic 99v999.
               05 WT-All-Students-Credits  pic 999.
          *
           Procedure Division.
          *
           000-Main-Rtn.
          *
               Perform 100-Init-Rtn Thru 100-Init-Rtn-Exit
                   Until WD-Response = 'no'
               Perform 200-Process-Rtn Thru 200-Process-Rtn-Exit
                   Until WD-Response = 'no'
               Perform 300-Display-Rtn Thru 300-Display-Rtn-Exit
               Display 'END OF SESSION'.
          *
           100-Init-Rtn.
          *
               Display 'Please enter your student number & press enter key'
               Accept WF-Student-Number
               Display 'Please enter the course number & press enter key'
               Accept WF-Course-Number
               Display 'Please enter the number of credits & press enter'
               Accept WF-Credit-Hours
               Display 'Please enter your grade & press enter key'
               Accept WF-Grade.
               If WF-Grade = 'A'
                   Add 4 to WF-Grade
               If WF-Grade = 'B'
                   Add 3 to WF-Grade
               If WF-Grade = 'C'
                   Add 2 to WF-Grade
               If WF-Grade = 'D'
                   Add 1 to WF-Grade
               If WF-Grade = 'F'
                   Add 0 to WF-Grade
               Add WF-Credit-Hours to WT-Credits
               Add WF-Grade to WT-Total-Grade
               Display 'Do you have another class to enter yes/no?'
               Accept WD-Response
               if WD-Response = 'no'
                   Display WF-Student-Number
               Divide WT-Total-Grade by WT-Credits giving WT-Cumlative
                   Display WT-Cumlative
               Add WT-Cumlative to WT-All-Students-GPA
               Add WT-Credits to WT-All-Students-Credits.
    
          *
           100-Init-Rtn-Exit. Exit.
          *
           200-Process-Rtn.
          *
               Initialize WD-Response
               Initialize WD-New-Student
               Display 'Is there another students GPA you wish to
          -'enter yes/no'.
               if WD-New-Student = 'yes'
                   add 1 to WT-Student-Count
               Accept WD-New-Student
               Display 'Please enter your student number & press enter key'
               Accept WF-Student-Number
               Display 'Please enter the course number & press enter key'
               Accept WF-Course-Number
               Display 'Please enter the number of credits & press enter'
               Accept WF-Credit-Hours
               Display 'Please enter your grade & press enter key'
               Accept WF-Grade.
               Display 'Do you have another class to enter yes/no'
               Accept WD-Response.
               if WD-Response = 'no'
                   Display WF-Student-Number
                   Divide WT-Total-Grade by WT-Credits giving WT-Total-Grade
                   WT-Credits
                   Display WT-Cumlative
               Add WT-Cumlative to WT-All-Students-GPA
               Add WT-Credits to WT-All-Students-Credits.
    
           200-Process-Rtn-Exit.  Exit.
          *
           300-Display-Rtn.
          *
               Divide WT-All-Students-GPA into WT-All-Students-Credits
               Display WT-All-Students-Credits.
          *
           300-Display-Rtn-Exit.  Exit.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2006
    Posts
    271
    Rep Power
    16
    My old 87' vintage Microfocus compiler wouldn't compile it. It threw three syntax errors. Two missing periods and an undeclared function name.

    Are you sure its even compiling?
  4. #3
  5. Commie Mutant Traitor
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2004
    Location
    Alpharetta, GA
    Posts
    1,806
    Rep Power
    1570
    Now, I only have a passing familiarity with COBOL, but if I recall correctly,
    Code:
    05 WF-Grade                 pic 99.
    declares WF-Grade as a 2-digit decimal value, right? Whereas in Init-Rtn, you use it first as a character value, then as a decimal:
    Code:
               Display 'Please enter your grade & press enter key'
               Accept WF-Grade.
               If WF-Grade = 'A'
                   Add 4 to WF-Grade
               If WF-Grade = 'B'
                   Add 3 to WF-Grade
               If WF-Grade = 'C'
                   Add 2 to WF-Grade
               If WF-Grade = 'D'
                   Add 1 to WF-Grade
               If WF-Grade = 'F'
                   Add 0 to WF-Grade
    Furthermore, there's no short-circuiting of the tests; even once you have the numeric value of WF-Grade assigned, you are still comparing it (up to four times) with a character value.

    I suspect what you meant to do is have another variable, say,
    Code:
    05 WF-Letter-Grade                 pic X.
    in which to hold the letter grade. For the other part, once you fix the variables it shouldn't make a difference for the program flow, but it may slow things down a bit; I think you'd be better off replacing the IF statements with a SEARCH on a table with the pairs of letter grades and grade values (don't recall how you do that offhand, or even if I have the keyword right). Otherwise, you'll need to use nested IF/ELSE/END-IFs to avoid repeatedly testing the value unnecessarily.

    It sounds like whatever compiler you're using is very lax on syntax checking...
    Last edited by Schol-R-LEA; February 16th, 2007 at 02:11 AM.
    Rev First Speaker Schol-R-LEA;2 JAM LCF ELF KoR KCO BiWM TGIF
    #define KINSEY (rand() % 7) λ Scheme is the Red Pill
    Scheme in Short Understanding the C/C++ Preprocessor
    Taming Python A Highly Opinionated Review of Programming Languages for the Novice, v1.1

    FOR SALE: One ShapeSystem 2300 CMD, extensively modified for human use. Includes s/w for anthro, transgender, sex-appeal enhance, & Gillian Anderson and Jason D. Poit clone forms. Some wear. $4500 obo. tverres@et.ins.gov
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Location
    Platteville, WI
    Posts
    23
    Rep Power
    0
    Sweet, thanks for the help. You're right about inputting a number compared to a letter. Totally missed that.

    As for a compiler, on this first program he made us use PersonalCobol. The next one we are using something else, not sure of the name.

IMN logo majestic logo threadwatch logo seochat tools logo