QBASIC homework help NEWBIE!

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
JasonQuinn1992
Coder
Posts: 42
Joined: Mon Sep 03, 2012 4:32 pm

QBASIC homework help NEWBIE!

Post by JasonQuinn1992 »

Hello,

I am taking a BASIC programming class in college using QBASIC and have been asked as an homework assignment to write a program that will input a number and print the number, the square of the number, and the cube of the number. Continue the operation until 999 is entered. My problem is that once I code the program and attempt to run it the operation stops and I get a bunch of zeros in the "Run" menu. Here is the code I am using:

*************************************************************
REM
REM *** This a program to find the square and cube of a number ***
REM *****************************************************************
REM
REM ***PROGRAM MAIN BODY***
CLS

GOSUB InitializeScreen
GOSUB InputData
GOSUB PrintData
RETURN
END

REM *************************************
REM *** Initialize Screen ***
REM *************************************

InitializeScreen:
CLS
RETURN

REM ***************************************
REM ***Print Data ***
REM ***************************************

InputData:
INPUT "Get number from user:$"; GivenNum
INPUT "DO until:$"; GivenNum999
INPUT "Square the number:$;"; GivenNum^ 2
INPUT "Cube the number:$;" GivenNum^3
CLS
END

LOOP

PrintData:

PRINT
PRINT "Get number from user:$"; GivenNum
PRINT "Square the number:$;"; GivenNum ^ 2
PRINT "Cube the number:$;"; GivenNum ^ 3
LOOP
END

The problem i'm having is that after the "PRINT "Square the number:$;"; GivenNum ^ 2" line I get an ", or end-of-statement error... can someone please help me fix this

Thank you!
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

You can't square or do any math to the number in the INPUT statements. Do it after it is input.

Your DO LOOP should keep the program running until 999 is entered. Did you copy the program wrong? The DO is in the INPUT statement.

All you need is one INPUT to get the number. Then do the math and if the user entry is 999 exit the loop or use EXIT DO.

PS: Tell your teacher to try QB64.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
JasonQuinn1992
Coder
Posts: 42
Joined: Mon Sep 03, 2012 4:32 pm

Post by JasonQuinn1992 »

Thank you so much I was able to get it to work :)
Post Reply