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

    Join Date
    Jan 2006
    Location
    Scotland
    Posts
    5
    Rep Power
    0

    Pseudocode to count integers


    Hi

    I need some help. Does anyone know the pseudocode to count integers in a file?

    Thanks in advance!
  2. #2
  3. guru
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    SW1A London UK
    Posts
    608
    Rep Power
    0
    a little bit vague! How about giving us the file?

    did u mean. How to count the number of values in a file e.g. 10 lines with 10 values or something else?
    Create, Inspire & enjoy
  4. #3
  5. (retired)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2003
    Location
    The Laboratory
    Posts
    10,101
    Rep Power
    0
    let me guess, it's a homework assignment?

    --Simon
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2006
    Location
    Scotland
    Posts
    5
    Rep Power
    0
    It is the number of integers that are in the file not the values. It could be thought of as homework.

    Suzie
  8. #5
  9. (retired)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2003
    Location
    The Laboratory
    Posts
    10,101
    Rep Power
    0
    so what have you tried?
  10. #6
  11. guru
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    SW1A London UK
    Posts
    608
    Rep Power
    0
    yeah come on!

    its homework for a reason!! at least give it a go b4 looking for the answer! otherwise ur not gonna learn!
    Create, Inspire & enjoy
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2006
    Location
    Scotland
    Posts
    5
    Rep Power
    0
    Ok I have not used pseudocode before but here is my effort:

    Begin procedure to count how many integers are in the file
    Add integers to array list If array = empty Then Msg box show “There is no data in the file”
    Statement is true
    End If
    If statement is false Then
    COUNT integers (variables) and loop until no more integers
    Store in the variable then output to text box End If
    End procedure
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2006
    Location
    Scotland
    Posts
    5
    Rep Power
    0
    How far off the track am I?
  16. #9
  17. guru
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    SW1A London UK
    Posts
    608
    Rep Power
    0
    you've done ok!

    from my experience of writing Pseudocode for Uni they usuaully expect a little bit more detail and evaluation of variables u used.

    For example you simply put :

    "COUNT integers and loop until no more integers"

    By the sounds of it this is the most important part of the Pseudo code and you have wrapped it up in one line.

    Personally i would break this down into a While loop

    e.g Pseudo code:
    int ll_count //counting variable
    boolean lb_continue = true

    while lb_continue = true (condition = true) // u use a while loop when u do not know how many variables you are reading in.

    Read variable in
    if exists = false (if there is a value) // you could change this to is it EOF
    lb_condition = false //exiting the while loop
    else
    isit a number // a bit of validation to make sure it is infact a number
    if yes
    ll_count add one
    end if
    end if
    loop


    thats roughly what i would do for that main part. But you still have to go into more detail baout locating the file and opeinging it.

    hope that helps!
    Create, Inspire & enjoy
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2006
    Location
    Scotland
    Posts
    5
    Rep Power
    0
    Hi

    This is really helpful thank you. I will work on it more today.

    Suzie
  20. #11
  21. fork while true;
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2005
    Location
    England, UK
    Posts
    5,538
    Rep Power
    1051
    In the pseudocode we've used, the only form of loop available was like so

    repeat
    ...
    until <condition>

    so you'd do something like this

    repeat
    read line from file 1
    if line is an integer
    increment numberOfValues
    store line in array `values`
    end if
    until numberOfValues = 10

IMN logo majestic logo threadwatch logo seochat tools logo