| | |
Getting the average of the sum.
![]() |
hi, can anyone help me with my codes. I can't find the right solution for getting the average of the sum. For example, my first number is 1 and the second is 10. It will get the sum of either all the even nos there or the odd nos there. And then it will get the average of it. Pls help me. tnx.
TAKEHOME.COB Wed Dec 03 17:08:51 2008 Page 1 line number source line Microsoft COBOL Version 2.20 1 IDENTIFICATION DIVISION. 2 PROGRAM-ID. Iteration-If. 3 AUTHOR. Michael Coughlan. 4 5 ENVIRONMENT DIVISION. 6 7 DATA DIVISION. 8 9 WORKING-STORAGE SECTION. 10 01 Num1 PIC 99 VALUE ZEROS. 11 01 Num2 PIC 99 VALUE ZEROS. 12 01 Result PIC 999 VALUE ZEROS. 13 01 Sum-Nos PIC 999 VALUE ZEROS. 14 01 Prod-Nos PIC 999 VALUE 1. 15 01 Ave-Nos PIC 99.99 VALUE ZEROS. 16 01 Counter PIC 99 VALUE ZEROS. 17 01 Operator PIC X VALUE SPACE. 18 01 Answer PIC X VALUE SPACE. 19 01 CHECKEVEN PIC 99 VALUE ZEROS. 20 01 CHECKODD PIC 99 VALUE ZEROS. 21 22 PROCEDURE DIVISION. 23 24 Main. 25 DISPLAY "Enter First Integer: ". 26 ACCEPT Num1. 27 DISPLAY "Enter Second Integer: ". 28 ACCEPT Num2. 29 DISPLAY "Choose 0/E/A: ". 30 ACCEPT Answer. 31 IF Answer = "O" 32 PERFORM Odd 33 ELSE 34 IF Answer = "E" 35 PERFORM Even 36 ELSE 37 IF Answer = "A" 38 PERFORM Gabos 39 ELSE 40 DISPLAY "Invalid Input!". 41 42 Gabos. 43 PERFORM Get-Values 44 VARYING Num1 FROM Num1 BY 1 45 UNTIL Num1 > Num2. 46 DISPLAY "The Sum is: ", Sum-Nos. 47 DISPLAY "The Product is: ", Prod-Nos. 48 COMPUTE Ave-Nos = Sum-Nos / Num2. 49 DISPLAY "The Average is: ", Ave-Nos. 50 STOP RUN. 51 52 Even. 53 COMPUTE CHECKEVEN = Num1 / Num1. 54 IF CHECKEVEN = 1 55 PERFORM Get-Values 56 VARYING Num1 FROM Num1 BY 2 57 UNTIL Num1 > Num2 58 ELSE 59 COMPUTE Num1 = Num1 + 1 60 PERFORM Get-Values 61 VARYING Num1 FROM Num1 BY 2 62 UNTIL Num1 > Num2. 63 DISPLAY "The Sum is: ", Sum-Nos. 64 DISPLAY "The Product is: ", Prod-Nos. 65 COMPUTE Counter = Num2 - Num1 + 0.5. 66 COMPUTE Ave-Nos = Sum-Nos / Counter. 67 DISPLAY "The Average is: ", Ave-Nos. 68 STOP RUN. 69 70 Odd. 71 COMPUTE CHECKODD = Num1 / Num1. 72 IF CHECKODD = 1 73 PERFORM Get-Values 74 VARYING Num1 FROM Num1 BY 2 75 UNTIL Num1 > Num2 76 ELSE 77 COMPUTE Num1 = Num1 + 1 78 PERFORM Get-Values 79 VARYING Num1 FROM Num1 BY 2 80 UNTIL Num1 > Num2. 81 DISPLAY "The Sum is: ", Sum-Nos. 82 DISPLAY "The Product is: ", Prod-Nos. 83 COMPUTE Counter = Num2 - Num1 + 0.5. 84 COMPUTE Ave-Nos = Sum-Nos / Counter. 85 DISPLAY "The Average is: ", Ave-Nos. 86 STOP RUN. 87 88 Get-Values. 89 COMPUTE Sum-Nos = Sum-Nos + Num1. 90 COMPUTE Prod-Nos = Prod-Nos * Num1. 91
![]() |
Similar Threads
- need help with getting average using java servlet (Java)
- Determin the average of an array that generates 30 random numbers. (C++)
- Pascal Average Program Question (Pascal and Delphi)
- average array (C++)
- Errors in counting number of elements of the array greater and lesser than average (C)
- C++ : Calculating the average value of an array (C++)
- user input random amount display average. little problem i have run into (Java)
- How can I get Highest, Lowest and Average ? (C++)
Other Threads in the Legacy and Other Languages Forum
- Previous Thread: NATURAL data types
- Next Thread: Contemporary issues in the design of programming languages
| Thread Tools | Search this Thread |





