Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

HELP WITH THIS PSEUDOCODE PLEASE!

papakaitpapakait Member Posts: 4
Can anyone help me write a pseudocode for this problem please?


Write a program that inputs an even integer from the user (we will refer to this as x in the rest of the handout) and outputs all even numbers between zero and the input number (inclusive).

Hints:

1. Remember to declare needed variable(s). How many variables do you need and of what type?

2. The problem statement is essentially asking you to print the number sequence 0 2 4 6

Comments

  • OMichaelOMichael Member Posts: 13
    [code]declare x, count as integer

    count = 0

    do until count >= x

    print count & ", "
    count = x + 2

    loop[/code]

    Hope this helps
  • ActorActor Member Posts: 447 ✭✭
    [code]
    integer X, Count

    read X
    for Count = 0 to X step 2
    write Count
    [/code]

    Or if you [italic]must[/italic] use a [b]while[/b] loop..

    [code]
    integer X, Count

    read X
    Count = 0
    while Count <= X
    write Count
    Count = Count + 2
    [/code]

  • ActorActor Member Posts: 447 ✭✭
    : [code]: declare x, count as integer
    :
    : count = 0
    :
    : do until count >= x [red]// does not handle "inclusive" case[/red]
    :
    : print count & ", "
    : count = x + 2 [red]// wrong![/red]
    :
    : loop[/code]:
    :
    : Hope this helps
    :

  • papakaitpapakait Member Posts: 4
    thanks so much!
  • OMichaelOMichael Member Posts: 13

    [code]
    : declare x, count as integer
    :
    : count = 0
    :
    : do until count >= x + 2 // fixed i think, i have no way to debug :(
    : print count & ", "
    : count = count + 2 // fixed :)
    : [/code]
  • ActorActor Member Posts: 447 ✭✭
    :
    : [code]:
    : : declare x, count as integer
    : :
    : : count = 0
    : :
    : : do until count >= x + 2 [red]// will allow case x+1 if x is odd[/red]
    : : print count & ", "
    : : count = count + 2 // fixed :)
    : : [/code]:
    :

  • papakaitpapakait Member Posts: 4
    I tried using Actors but it isn't working. It says the words "write" and/or "read" aren't declared. Im writing this for CH is there any other way I can do it, or other words? (We've been using cout and cin things)?

    Now that you have been working on Ch programs for the past few weeks, you should have become more familiar with the process of translating a problem/solution description into code. In this lab, you are given a problem statement that makes use of the programming elements learned over the past few weeks. You are expected to devise an algorithm to solve this problem and translate it into code. You are expected to work on your own. Some hints are given at the end of this handout to help you with this process. Remember that your code will not look like everyone else
  • ActorActor Member Posts: 447 ✭✭
    : I tried using Actors but it isn't working. It says the words
    : "write" and/or "read" aren't declared.

    Your request was for an algorithm in pseudo code. By definition pseudo code is not likely to compile. "write" and "read" are generic terms and you need to translate into whatever the equivalent is in the language you are using.

    I've no idea what CH is but if you are using cin and cout it seems you are using something similar to C++, which would look something like this.
    [code]
    main()
    {
    int x, count ;

    cin >> x ;
    count = 0 ;
    while (count <= x){
    cout << x ;
    count += 2 ;
    }
    [/code]

Sign In or Register to comment.