![]() |
|
![]() | ||
|
Subject:
Qbasic Problem
Category: Computers > Programming Asked by: mrfony-ga List Price: $2.00 |
Posted:
17 Sep 2002 17:10 PDT
Expires: 17 Oct 2002 17:10 PDT Question ID: 66191 |
What is logically wrong with the following program? INPUT D, E D = E / F Print "The answer is" ; D End |
![]() | ||
|
Subject:
Re: Qbasic Problem
Answered By: coldfusion-ga on 17 Sep 2002 18:11 PDT |
Hello! The simple answer to this question is that you are trying to divide by zero. Since you are attempting to divide E by F, qbasic wonders 'Where is this F you're talking about?!'. Not finding it, it assigns a value of 0 to it. Thus, the program you gave will show as: INPUT D, E D = E / 0 Print "The answer is" ; D I believe what you meant to do was: INPUT D, E F = D / E Print "The answer is" ; F You may wish to do some simple syntax checking as well to make sure the USER doesn't enter a 0. With syntax checking the syntax would be: INPUT D, E if e > 0 then f = d / e print "The answer is "; F else print "You cannot divide by 0!" end if Thanks! Todd | |
| |
|
![]() | ||
|
Subject:
Re: Qbasic Problem
From: pinkfreud-ga on 17 Sep 2002 17:17 PDT |
If F is not defined, then isn't this the same thing as dividing by zero? |
Subject:
Re: Qbasic Problem
From: sherlockh-ga on 17 Sep 2002 18:05 PDT |
The program asks for the user to input variables d and e, but then divides e by f (when f hasn't been defined, so will give a 'division by zero error') Also, the program could also tell the user what it is doing, ie. the program says "this answer is ', but it doesn't tell the user what the calculation was, eg. it could say: INPUT D,E ANSWER=D/E PRINT D;" divided by ";e;" is ";answer |
Subject:
Re: Qbasic Problem
From: sherlockh-ga on 17 Sep 2002 18:12 PDT |
So what it is doing which is logically wrong is: In it's calculation it is using a variable that has not been defined (f) ie. f has not been set to a value before e is divided by f |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |