Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
CCC 2003 Stage1: S1J3: Snakes and Ladders
Author Message
Tony

Posted: Sat Mar 22, 2003 1:19 pm   Post subject: CCC 2003 Stage1: S1J3: Snakes and Ladders

Each player throws a part of dice to determine how many squares his/her game piece will advance. If the piece lands on the bottom of a ladder, the piece moves up to the square at the top of the ladder. If the piece lands on the top of a snake, the piece "slides" down to the square at the bottom of the snake. If the piece lands on the last square, the player wins. If the piece cannon advance the number of squares indicated by the dice, the piece in not moved at all.

In order to help you play this game via a cell phone while travelling, you will write a program that simulates your moves on the board shown and, ofcourse, runs on your handheld computer. If you got a handheld computer, why are you playing in snakes&ladder via cellphone?! - Confused Tony You will repeatedly throw the dice and enter the result into the program. After each throw the program will report the number of the square wher your piece lands.

When the program starts it should assume the piece is on square 1. It should repeatedly read input from the user (a number meaning integer between 2 and 12) and report the number of the square where the peice lands. In addition, if the piece moves to the last square, the program should print "You Win!" and terminate. If the user enter 0 instead of a number between 2 and 12, the program should print "You Quit!" and terminate.

For clarity, you are to use the board pciture above and you should note that the board has 3 snakes (from 54 to 19, from 90 to 48, from 99 to 77) and 3 ladders (from 9 to 34, from 40 to 64 and from 67 to 86).

The board itself is 100 squares long, you win when you reach 100th square

Solution by JSBN
 code: var sum : int var loca : int := 1 loop     put "Enter sum of dice:"     get sum     if sum = 0 then         put "You Quit!"         quit     end if     if loca + sum > 100 then     else         loca := loca + sum     end if     if loca = 9 then         loca := 34     elsif loca = 40 then         loca := 64     elsif loca = 67 then         loca := 86     elsif loca = 99 then         loca := 77     elsif loca = 90 then         loca := 48     elsif loca = 54 then         loca := 19     end if     put "You are now on square ", loca     exit when loca = 100 end loop put "You Win!"

This is easier then both J1 and J2... what were they thinking?
Tony's programming blog. DWITE - a programming contest.

Office of the Registar

Posted: Fri Apr 25, 2003 9:08 am   Post subject: (No subject)

ya that question was pretty easy
Andy

Posted: Sat Jun 07, 2003 8:24 pm   Post subject: (No subject)

i forgot to put you are on square 100
i just put you win
damn, lost 1 mark, dropped me 4 places
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 3 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: