Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 27th, 2008, 5:41 PM   #1
Ryuk
Newbie
 
Join Date: Oct 2008
Posts: 1
Rep Power: 0 Ryuk is on a distinguished road
Qbasic

I'm fairly new to programming. I have this problem where AX + B = C and I have to solve for X. I am using QBASIC 4.5 to write this program.

Here is my code.
Quote:
OPEN "SCRN:" FOR OUTPUT AS #1
COLOR 2, 0
CLS
PRINT #1, TAB(30); "Solving for X"
PRINT #1,
PRINT #1, TAB(20); "Equation"; TAB(55); "X="
PRINT #1, STRING$(80, 207)
EquationProgram:
READ A, B, C
IF A = 9999 THEN END
IF X = (C - B) / A THEN
PRINT #1, TAB(20); A * X + B = C; TAB(55); X
END IF

GOTO EquationProgram

DATA 9999,9999,9999
DATA 3,6,1
DATA 7,10,9
DATA 8,12,11
DATA 9,15,14
DATA 14,19,15
DATA 19,17,14
When I run the program it does not display the equation or the X variable. What am I doing wrong?
Ryuk is offline   Reply With Quote
Old Oct 27th, 2008, 6:32 PM   #2
lectricpharaoh
SEXY SHOELESS GOD OF WAR!
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,676
Rep Power: 10 lectricpharaoh will become famous soon enough
Re: Qbasic

Quote:
Originally Posted by Ryuk
When I run the program it does not display the equation or the X variable. What am I doing wrong?
Comment out your first DATA statement. When it reads in 9999, the test IF A = 9999 THEN END causes the program to exit.
Quote:
Originally Posted by Ryuk
I'm fairly new to programming. I have this problem where AX + B = C and I have to solve for X. I am using QBASIC 4.5 to write this program.
This raises a more important point: why are you using QBasic for this? There are many languages that are not only more powerful, but are much less likely to encourage bad programming habits. Since you're likely on a Windows box, I'd recommend C#, but C++ is an excellent choice too, and I've heard good things about Python.
__________________
My microwave has settings for snake, gremlin, and puppy.
lectricpharaoh is offline   Reply With Quote
Old Oct 27th, 2008, 6:42 PM   #3
Grich
Professional Programmer
 
Grich's Avatar
 
Join Date: Sep 2007
Location: Sydney - Australia
Posts: 424
Rep Power: 7 Grich is on a distinguished road
Re: Qbasic

Quote:
Originally Posted by Ryuk View Post
GOTO EquationProgram
Ah ... GOTO statements, they brign back memories (painful ones). lectricpharaoh is right. If you want to learn programming these days, you need a language that relates to modern programming. I recommend Python. QBASIC is great for new guys, if you want to use it though, you need to be using it wisely and not use GOTO statements. Look into while loops and for loops in QBASIC.
__________________
SYNTAX ERROR ...
Grich is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
QBasic Antidisestablishmentarian Other Programming Languages 13 Jan 23rd, 2006 5:28 AM
Help with Qbasic coldfx Other Programming Languages 0 Dec 17th, 2005 2:57 AM
QBasic Clotters Other Programming Languages 3 May 27th, 2005 8:11 PM
Help in QBASIC (I think it's similar to VB) phoenix987 Visual Basic 3 May 9th, 2005 12:33 PM
Help with a QBASIC program phoenix987 Other Programming Languages 4 May 5th, 2005 12:27 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:40 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC