
-----------------------------------
nin
Tue Nov 21, 2006 7:20 pm

var topic
-----------------------------------
im workin on a worksheet that my teacher gave me n its due tomorrow. I dont really know what to do on the last 3 assignments. and so far im having difficulties...n this is my code so far:

loop
    %Declaration Section
    var number : int
    var answer : int := 28

    %Program Title
    locate (1, 34)
    put "Guessing Game"

    %Program intorduction
    locate (3, 1)
    put "See if you can guess a number between ten and thirty!"

    %User Input
    locate (5, 1)
    put "Enter a number between 10 and 30:" ..
    get number
    
    %Possible guess results
    if number >= 29 then
        put "You need to come down a little!" ..

    elsif number = 28 then
        put "Good job!" ..

    elsif number >= 10 then
        put "Way down there?" ..

    end if

end loop


%End of Program


the assignments are the following:
a) add an if structure so that only an input between ten and thirty will be accepted. Test your program. Then input section will repeat until the user enters the correct value.

Add an if structure so that only one of the possible guess will output. Test your program. Save it as IfStructure3.t Print source code and hand it in with this assignment.

b) add a for loop structure so that the program will execute four times. Test your program.

c)Add a for loop structure so that the program will execute four times and exit if the user guesses the correct answer before the fourth time. Test your program.

so how can i do the following assignments... and am i on the right track so far?


[/quote]

-----------------------------------
Expirant
Wed Nov 22, 2006 7:59 am


-----------------------------------
I think you're starting to get on the right track for question a). A couple things you may want to consider though is instead of declaring the answer right at the beginning of the code, use a variable to hold its value to make it easier for you or the teacher to read and possibly allow you to change it to a random number.

And checking if a number is between two numbers should look something like:
if userNum >= lowerBound and userNum = 29 then
        put "You need to come down a little!" ..

    elsif number = 28 then
        put "Good job!" ..

    elsif number >= 10 then
        put "Way down there?" ..

    end ifMissing things like this happen when linear algebra, physics, and sleep deprevation come together.  Not being allowed to edit posts is also a problem.

Oh, and might I suggest you change the following line so you do not have to hardcode the number in twice.
elsif number = 28 thenAs I recall, you created a variable called answer that holds this number already ;-).
