0

I am trying to write a procedure that will produce the following output

exec WinOrLose(4)

Welcome to the Win or Lose Game. Your number is 4. 

You win.
You lose.
You win.
You lose.

==> You lose!

So far I have this:

CREATE or REPLACE Procedure WinOrLose (
  p_choice number ) AS

  v_answer number;

DECLARE
  v_answer := p_choice

BEGIN
  dbms_output.put_line ('Welcome to the Win or Lose Game. Your number is ' || 
  v_answer);

  FOR v_answer in 1..10 
    IF MOD(v_answer, 2) = 0 THEN -- v_answer is even
          dbms_output.put_line (You lose)

END;
/

I'm unsure of where to go from there. My thought process (psuedocode) is this:

SET v_answer := 1
   While Loop (outside)
     MOD(v_answer,2) = 0 then dbms.output (YOU LOSE)
   ELSE
     dbms.output (YOU WIN)
   end if;
     v_answer := p_choice
1
  • What are the rules? Looking at the code and pseudo code nothing makes any sense. Commented Oct 10, 2017 at 13:46

1 Answer 1

2
CREATE or REPLACE Procedure WinOrLose (
  p_choice number ) AS
BEGIN
  dbms_output.put_line ('Welcome to the Win or Lose Game. Your number is ' || 
  p_choice);

  FOR v_counter in 1..p_choice LOOP
    IF (MOD(v_counter, 2) = 0) 
    THEN
          dbms_output.put_line ('You win');
    ELSE
          dbms_output.put_line ('You lose');
    END IF;
  END LOOP;

  IF (MOD(p_choice , 2) = 0) 
  THEN
    dbms_output.put_line ('==> You win!');
  ELSE
    dbms_output.put_line ('==> You lose!');
  END IF;
END;
/
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you! Last question, how would I output "==> You lose!" or "==> You win!" at the end?
@Lizzie You are welcome! I have edited it, let me know if it is working. Best.
Thank you so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.