Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

printing using "print using"--help!!!!

ofnir1ofnir1 Member Posts: 9
Hey guys! So I wrote this program and everything seems to be working fine excpet for the fact that when I run it, under the degree column, a percent sign (%) is also printed. I also noticed that the final tangent value does the same thing and isn't rounded like the rest of the values. Can you guys help please?

10 REM LUIS BOBADILLA, 05/03/08, COACH, D2, 11:10-12:30
20 REM THIS PROGRAM TAKE DEGREES 0-90 IN INCREMENTS OF 10 AND THEN COMPUTES THE RADIANS, SIN, COS, AND TANGENT OF EACH DEGREE.
30 A$ = " #.# #.### #.###/#.### #.###"
40 PRINT "DEGREES",,"RADIANS",,,"COS/SIN",,,"TAN"
50 FOR X = 0 TO 90 STEP 10
60 LET R = (X*PI/180)
70 LET C = COS (R)
80 LET S = SIN (R)
90 LET T = TAN (R)
100 PRINT USING A$;X, R, C, S, T
110 NEXT X
120 END
Ok
RUN
DEGREES RADIANS COS/SIN TAN
0.0 0.000 1.000/0.000 0.000
%10 0.175 0.985/0.174 0.176
%20 0.349 0.940/0.342 0.364
%30 0.524 0.866/0.500 0.577
%40 0.698 0.766/0.643 0.839
%50 0.873 0.643/0.766 1.192
%60 1.047 0.500/0.866 1.732
%70 1.222 0.342/0.940 2.747
%80 1.396 0.174/0.985 5.671
%90 1.571 0.000/1.000 %1.631778728384

Comments

  • zibadianzibadian Member Posts: 6,349
    : Hey guys! So I wrote this program and everything seems to be working
    : fine excpet for the fact that when I run it, under the degree
    : column, a percent sign (%) is also printed. I also noticed that the
    : final tangent value does the same thing and isn't rounded like the
    : rest of the values. Can you guys help please?
    :
    : 10 REM LUIS BOBADILLA, 05/03/08, COACH, D2, 11:10-12:30
    : 20 REM THIS PROGRAM TAKE DEGREES 0-90 IN INCREMENTS OF 10 AND
    : THEN COMPUTES THE RADIANS, SIN, COS, AND TANGENT OF EACH DEGREE.
    : 30 A$ = " #.# #.### #.###/#.###
    : #.###"
    : 40 PRINT "DEGREES",,"RADIANS",,,"COS/SIN",,,"TAN"
    : 50 FOR X = 0 TO 90 STEP 10
    : 60 LET R = (X*PI/180)
    : 70 LET C = COS (R)
    : 80 LET S = SIN (R)
    : 90 LET T = TAN (R)
    : 100 PRINT USING A$;X, R, C, S, T
    : 110 NEXT X
    : 120 END
    : Ok
    : RUN
    : DEGREES RADIANS COS/SIN TAN
    : 0.0 0.000 1.000/0.000 0.000
    : %10 0.175 0.985/0.174 0.176
    : %20 0.349 0.940/0.342 0.364
    : %30 0.524 0.866/0.500 0.577
    : %40 0.698 0.766/0.643 0.839
    : %50 0.873 0.643/0.766 1.192
    : %60 1.047 0.500/0.866 1.732
    : %70 1.222 0.342/0.940 2.747
    : %80 1.396 0.174/0.985 5.671
    : %90 1.571 0.000/1.000
    : %1.631778728384
    :
    :
    I can understand the result for the tan(90 deg). In maths the tangent function is defined as being the sin over the cos (i.e. tan = sin/cos). In case of 90 degrees, cos equals 0. This causes a division by zero error. Instead of throwing some kind of error, your basic interpreter/compiler just gets lost and doesn't know how to handle the results, and thus also failing to apply the basic formatting.
    As for the %-sign before each degrees value (except the first), my guess is that that's the way your interpreter/compiler shows that that value is precise instead of rounded. The first degrees value is taken as a floating point, but every other iteration of the for-loop has changed X into an integer. Thereby removing any rounding it would need.
  • ofnir1ofnir1 Member Posts: 9
    wow, I totaly failed to see the division by zero there. thanks for the help!
Sign In or Register to comment.