Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Help with random number guess game
Author Message
josh

Posted: Fri Feb 13, 2004 9:01 pm   Post subject: Help with random number guess game

I am trying to create this random number guess game and I need a little help. I want to make it so that once the user is asked to confirm if they are ready to begin (y/n) that either answer will start the game but will put a different "put" stamtent on the screen

I am also having troubl writing the statment that ends the game (or if n e one can help with a loop restarts the game) if the user enters anything but an n or y

 code: var randmnumber, guess1, guess2, guess3 : int var name, yn : string %Making the random number randint (randmnumber, 1, 40) %introduction and getting name put "HELLO AND WELCOM TO THE RANDOM NUMBER GUESS GAME!!!!" put "I'm, your host Mr. Computer. Lets meet our contest!!!!" put "and your name is?" get name %Rules put "So today we have ", name, " with us. ", "Before we begin here, are the rules:" put "1. The number will be between 1 and 40" put "2. You will get three guesses" put "3. After each guess you will be given a hint to wether the number is higher or lower then your guess." put "Do you understnd these rules?" %Confirm ready to play put "Are you ready to play?" get yn         if yn = "y" then             put "good here we go"         end if         if yn = "n" then             put "To bad we are going to start anyways"         end if               if yn not="n" or "y" then             put "i am sorry the is not a valid answer please restart the game and answer with a y or n next time"         end if

Cervantes

Posted: Fri Feb 13, 2004 9:22 pm   Post subject: (No subject)

shoulda read up on the syntax of if statements.. when you use 'or' / 'and' it doesn't keep the same beginning
hence
 code: if yn not= "n" or "y" then

is wrong. you need it to be like so
 code: if yn not= "n" or yn not= "y" then

also it should be and not or.

so here's your code with that problem fixed:

 code: var randmnumber, guess1, guess2, guess3 : int var name, yn : string %Making the random number randint (randmnumber, 1, 40) %introduction and getting name put "HELLO AND WELCOM TO THE RANDOM NUMBER GUESS GAME!!!!" put "I'm, your host Mr. Computer. Lets meet our contest!!!!" put "and your name is?" get name %Rules put "So today we have ", name, " with us. ", "Before we begin here, are the rules:" put "1. The number will be between 1 and 40" put "2. You will get three guesses" put "3. After each guess you will be given a hint to wether the number is higher or lower then your guess." put "Do you understnd these rules?" %Confirm ready to play put "Are you ready to play?" get yn if yn = "y" then     put "good here we go" end if if yn = "n" then     put "To bad we are going to start anyways" end if if yn not= "n" and yn not= "y" then     put "i am sorry the is not a valid answer please restart the game and answer with a y or n next time" end if

use a for statement for ending the game. read up on those and play around with it first, once you've tried your best only then come back here and ask for help
josh

Posted: Fri Feb 13, 2004 9:35 pm   Post subject: (No subject)

thanx for the help but I have read about 5 diffrent tutorials and I still can't figure out loops.

I am not trying to sue this forum to cheat on a project becasue this isn't even for school. i am jsut trying to self teach myself turing.
Cervantes

Posted: Fri Feb 13, 2004 9:43 pm   Post subject: (No subject)

good job. self teaching is pretty hard

I'll write you a loop tutorial tommorow morning. sorry I gotta get to bed early tonight
josh

Posted: Fri Feb 13, 2004 9:44 pm   Post subject: (No subject)

thanx for all the help and I really apreciate the tutorial.
Cervantes

Posted: Sat Feb 14, 2004 11:24 am   Post subject: (No subject)

All done the tutorial

http://www.compsci.ca/v2/viewtopic.php?p=33003#33003

hope it helps
josh

Posted: Sat Feb 14, 2004 12:20 pm   Post subject: (No subject)

thanks for the help this is a great tutorial. Really easy to understand
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 7 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: