Can some one help me with a command

Hey im 13 and just starting to get into Qbasic programing. I picked up the Computer Programing for dummies book, but theres one thing I'am stuck on. In there it creates a sample program to make. The program has you input your age. After that it will tell you something you can do at this age. Ex. 16 You can now drive.

I decieded to take this a litle farther by adding my own response. My problem is after they input one age I want the program to ask if it wants to play agian. Then wait for a Yes No answer. If yes it starts over and if No it ends the program. If some one can tell me how to enter I would apreciate it.



Thanx


Comments

  • 1



    'Insert your code here



    print "type yes if you would like to try again"

    input a$

    if a$="yes" then goto 1

    'If you want to see what you can really do in QBASIC, check out my game with 42 weapons at http://www.angelfire.com/nh/elfingo/botwarz.html




    URL:http://www.angelfire.com/nh/elfingo/botwarz.html

  • : Hey im 13 and just starting to get into Qbasic programing. I picked up the Computer Programing for dummies book, but theres one thing I'am stuck on. In there it creates a sample program to make. The program has you input your age. After that it will tell you something you can do at this age. Ex. 16 You can now drive.

    : I decieded to take this a litle farther by adding my own response. My problem is after they input one age I want the program to ask if it wants to play agian. Then wait for a Yes No answer. If yes it starts over and if No it ends the program. If some one can tell me how to enter I would apreciate it.

    :

    : Thanx

    :






  • No offence to Mr. Botwarz but I feel this method is both cleaner and screw-up free. both my answer and his work, but you shouldn't use goto's in your programs, this is called spaghetti programming and it is very very confusing.



    Try this:



    DO



    'Insert your code here



    PRINT "Would you like to try again? (Y/N)"

    DO

    answer$ = INKEY$

    answer$ = UCASE$(answer$)

    LOOP WHILE answer$ = "Y" or answer$ = "N"

    LOOP UNTIL answer$ = "N"



    Here's the explanation: I used a do loop to keep my program in a continuous loop. Then I ask the user if he/she wants to continue. the next line then has another do loop. this cause the program to stop and wait for the user to touch a key, hence 'answer$ = INKEY$'. That statement means that whatever was pressed on the keyboard will be stored in answer$. to continue on with the program, the user must hit either Y or N(upper or lower case), if not the loop will continue to wait. once the user does enter either a Y or N, the program will check if it was Y or N, if it was Y then the program will skip to the top and start over again, but if it's N then the program will end.






  • when I go to hit run after typing in Cam's code it highlights the word "loop" in LOOP UNTIL answer$ = "N" and says loop with out do.

    what does this mean.


  • First before I explain the error, I must point out that I messed up the first "loop" statement in the program. instead of "loop while answer$ = ...", it should be "loop until answer$ = ..."





    Now, on to the problem at hand. That specific error only pops up when the programmer has neglected to include a begin and end to a block of conditional code. That basically means that you have to check and match up all you "do, loops" in your program. However, You not only have to check your "do loop" statements to see if they match , but check all of your "if, endif's", "for next's","case select's" and so forth. That is most likely the cause of your problem.


  • You can set up a structure call a "do .. loop" just place your code between it and it will loop forever until the correct response is inputed. You're welcome.




Sign In or Register to comment.

Howdy, Stranger!

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

Categories