Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27

Thread: I need help

  1. #21
    Join Date
    Jan 2008
    Location
    Singapore
    Posts
    24
    Rep Power
    0

    Default

    Please give comment to my code. Thanks

    PSEUDO CODE

    1 INITIALIZE TOTAL_STD_COUNT = 0
    2 INITIALIZE TOTAL_FEMALE_STD = 0
    3 INITIALIZE AVG_AGE = 0
    4 OPEN STD_FILE
    5 INPUT “INDONESIA” AND “MULTIMEDIA”
    6 READ A RECORD (NATIONALITY, SUBJECT)
    7 LOOP UNTIL END OF FILE
    DO
    IF EVERY “NATIONALITY” AND “SUBJECT” MATCHES “INDONESIA” AND “MULTIMEDIA” THEN
    DISPLAY RECORD (STD_NO, STD_NAME, GENDER, AGE, SUBJECT, NATIONALITY)
    ELSE
    DISPLAY “NO RECORD FOUND”
    ENDIF
    IF EVERY “NATIONALITY” AND “SUBJECT” MATCHES “INDONESIA” AND “MULTIMEDIA” THEN
    ADD 1 TO TOTAL_STD_COUNT
    ELSE
    DISPLAY “NO RECORD FOUND”
    ENDIF
    8 INPUT “FEMALE”
    9 READ A RECORD (GENDER)
    10 IF EVERY “GENDER” MATCHES “FEMALE” THEN
    11 ADD 1 TO TOTAL_FEMALE_STD
    12 DISPLAY TOTAL_FEMALE_STD
    ELSE
    DISPLAY “NO RECORD FOUND”
    ENDIF
    12 INPUT “AVG_AGE”
    13 READ RECORD (AGE)
    IF EVERY “AGE” IS GREATER THAN 0 THEN
    ADD AGE TO TOTAL_AGE DIVIDE BY TOTAL_STD_COUNT
    DISPLAY AVG_AGE
    ENDIF
    14 ENDDO
    15 CLOSE STD_FILE
    Don Vito Corleone~I am gonna make you an offer you can't refuse

  2. #22
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Yes, well explained code it is. To me it better, except on thing. You have give inputs in different places. My advice is, do it in this way.

    Step 1: Initialize all variables used
    Step 2: User inputs handling
    Step 3: Do all the processing
    Step 4: Display results.

    Using those four steps, you can make your pseudo code much clear.

  3. #23
    Join Date
    Jan 2008
    Location
    Singapore
    Posts
    24
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Yes, well explained code it is. To me it better, except on thing. You have give inputs in different places. My advice is, do it in this way.

    Step 1: Initialize all variables used
    Step 2: User inputs handling
    Step 3: Do all the processing
    Step 4: Display results.

    Using those four steps, you can make your pseudo code much clear.
    So you mean organize all the inputs under 1 step?
    Don Vito Corleone~I am gonna make you an offer you can't refuse

  4. #24
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Yes, initialize all variables in step 1 that you want to use later in your application. Doesn't matter where you use it.

  5. #25
    Join Date
    Jan 2008
    Location
    Singapore
    Posts
    24
    Rep Power
    0

    Default

    Is It Something Like This But My Display Should I Actually Split Away From The Process? Will It Look Weird As To Which Process To Display?

    Pseudo Code

    1 Initialize Variables (total_std_count = 0, Indonesia And Multimedia = Nationality And Subject, Total_female_std = 0, Avg_age = 0)
    2 Open File “std_file”
    3 User Input Variables
    4 Process A Record
    5 Loop Until End Of File
    5 Read A Record (nationality, Subject)
    Do
    If Every “nationality” And “subject” Matches “indonesia” And “multimedia” Then
    Display Record (std_no, Std_name, Gender, Age, Subject, Nationality)
    Else
    Display “no Record Found”
    Endif
    If Every “nationality” And “subject” Matches “indonesia” And “multimedia” Then
    Add 1 To Total_std_count
    Else
    Display “no Record Found”
    Endif
    6 Read A Record (gender)
    7 If Every “gender” Matches “female” Then
    8 Add 1 To Total_female_std
    9 Display Total_female_std
    Else
    Display “no Record Found”
    Endif
    10 Read Record (age)
    If Every “age” Is Greater Than 0 Then
    Add Age To Total_age Divide By Total_std_count
    Display Avg_age
    Endif
    11 Enddo
    12 Close Std_file
    Don Vito Corleone~I am gonna make you an offer you can't refuse

  6. #26
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Actually I'm talking about the end result display. Not the error messages which you used in if-else conditions. You can't take out those error message away from the condition. If you take them out, your code going to be odd/unclear at all.

  7. #27
    Join Date
    Jan 2008
    Location
    Singapore
    Posts
    24
    Rep Power
    0

    Default

    Please check out my new thread thanks eranga.
    Don Vito Corleone~I am gonna make you an offer you can't refuse

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •