Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

round Cosine

Status
Not open for further replies.

OldWindows

Programmer
Mar 31, 2016
5
US
was making qbasic calculator... one choice is cos(number) and for the cos functions i use cos(number) and no matter what number i use the answer is one. I take it that the answer is too many digits long (prob nonteminating) and it rounds to an integer, however i would like it to round to say 6 decimal places to the left, eg. 5.234322 etc. How is this possible?
 
HI,

So what number are you using?

In general the number should be ....

(Degree * pi / 180)

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
??? sorry, i havent gone through much algebra, this is confusing, i am just trying to produce the calculator, i can give you the source code if you want.

i attatched BAS file of the source code you can view with qbasic and suggest improvement :)
 
 http://files.engineering.com/getfile.aspx?folder=8a6c4d6c-9307-4489-9d3b-7b48029a8f65&file=calc.bas
Again, what number are you using that, "the answer is one."?

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
oh i get it

The answer is any number does that. Absolutely any number.
 
sorry, i just got back from work and it was a crappy day and im TIRED :eek:
 
One test point is 60 degrees. COS should be .5 IIRC.

COS multiplier will never exceed 1 since the formula is adj/hyp.

Ed Fair
Give the wrong symptoms, get the wrong solutions.
 
i tried 60 degrees and it still says "1". ill paste the part of the code with the COS function

117 IF choice = 11 THEN PRINT "please enter your number"
IF choice = 11 THEN DIM csintimes
IF choice = 11 THEN INPUT csintimes
IF choice = 11 THEN LET p = csintimes
IF choice = 11 THEN LET a = COS(sintimes)
IF choice = 11 THEN PRINT "The answer is"; a
118 IF choice = 11 THEN PRINT
IF choice = 11 THEN PRINT "(1) exit the program"
IF choice = 11 THEN PRINT "(2) do more calculations"
IF choice = 11 THEN PRINT "(3) go back to the main menu"
IF choice = 11 THEN DIM cfpichoice
IF choice = 11 THEN INPUT cfpichoice
IF choice = 11 AND cfpichoice > 3 THEN PRINT "invalid number"
IF choice = 11 AND cfpichoice > 3 THEN GOTO 118
IF choice = 11 AND cfpichoice = 1 THEN STOP
IF choice = 11 AND cfpichoice = 2 THEN GOTO 117
IF choice = 11 AND cfpichoice = 3 THEN GOTO 100

The if choice = 11 things are there because choice 11 would trigger COS function.
 
Exactly what did you enter as the argument for cos? What is the value of sintimes?

I'd expect the value to be:
[tt]
1.04719 = 60 * 3.14159 / 180
[/tt]
Did you intend the input variable to be in csintimes?

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Based on your code, I know you are still learning to use QB.

You will need to have a " DOUBLE-LONG " variable memory space. PLEASE NOTE: this will eat up some of your 65k memory allocation to QB...use it sparingly or RE-use a common D-Long variable through-out your program AS NEEDED. (yes you can use " Single-Long " var however in the future you may need a double so why not start now?)

-->in QB's HELP menu select "DATA TYPES" and it will show you the ranges available.

-->in your code you'd have to fix a few things (note the changes in RED)

117 IF choice = 11 THEN PRINT "please enter your number"
IF choice = 11 THEN DIM csintimes#
IF choice = 11 THEN INPUT csintimes#
IF choice = 11 THEN LET p = csintimes
IF choice = 11 THEN LET a# = COS(csintimes#) <--This is a typo
IF choice = 11 THEN PRINT "The answer is"; a#
118 IF choice = 11 THEN PRINT

-->Good Luck and Good Reading, MiggyD


After pondering the riddle (for many years I might add) I finally got the answer (inadvertently through a movie): "If a tree falls in the forest and no one is around, does it make a sound?"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top