[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 264: mysqli_fetch_assoc(): Couldn't fetch mysqli_result
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 326: mysqli_free_result(): Couldn't fetch mysqli_result
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4149: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3027)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4149: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3027)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4149: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3027)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4149: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3027)
Pete's QBASIC Site • QBASIC homework help NEWBIE!
Page 1 of 1

QBASIC homework help NEWBIE!

Posted: Mon Sep 03, 2012 4:41 pm
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!

Posted: Mon Sep 03, 2012 6:10 pm
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.

Posted: Mon Sep 03, 2012 7:10 pm
by JasonQuinn1992
Thank you so much I was able to get it to work :)