Superscript and Rounding Issues
Author |
Message |
Joji

|
Posted: Wed Oct 26, 2011 12:29 pm Post subject: Superscript and Rounding Issues |
|
|
What is it you are trying to achieve?
I am trying to figure out how to do a superscript in Turing. Here is the question:
Quote: 2.1.14 Write a program that let you enter two numbers a,b, and that prints out a^b
I am also trying to figure out how to round numbers to 3 digits behind the decimal point.
What is the problem you are having?
I checked google, search bar, and the forums, but couldn't find the answer to how I could do a superscript in Turing like you would in Microsoft Office.
As for rounding, I used google, search bar, and the forums, but still no luck.
Describe what you have tried to solve this problem
Here is my attempted code:
code: | %Variables
var numA:real
var numB:real
%Inputing variables
put "Give me variable a"
get numA
put "Give me variable b"
get numB
%Printing results
put "The answer is ", numA, " to the power of ", numB, "." |
I know it's a stupid code, but I couldn't do anything else.
Here is my other code for rounding:
code: | %variables
var number : real
var rounded : real
%creating variables
put "Give me a crazy number."
get number
%calculating
rounded := number round(3)
%printing results
put "Trololol. Your crazy number was rounded to ", rounded, "." |
The code in "Calculating" is wrong... infact the use of round(3) or whatever is the incorrect syntex. What syntex should I use?
Please specify what version of Turing you are using
Turing 4.1.1
Many thanks.  |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Tony

|
Posted: Wed Oct 26, 2011 12:44 pm Post subject: RE:Superscript and Rounding Issues |
|
|
1. look closely at how superscript appears -- it's a slightly smaller font that's moved up from the line. You can't do that with put but you have all of the control over font sizes and positioning with Font.Draw, so you could figure things out there.
2. syntax/documentation -- round |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
Joji

|
Posted: Wed Oct 26, 2011 12:51 pm Post subject: RE:Superscript and Rounding Issues |
|
|
Tony, I want to round to 3 decimal places. How would I type that out. |
|
|
|
|
 |
Tony

|
Posted: Wed Oct 26, 2011 1:42 pm Post subject: RE:Superscript and Rounding Issues |
|
|
e.g. you want to round 1.234 to 2 decimal places. You then take a note that round(123.4) returns 123 -- just the digits you want. You'd just need to move the decimal point back to where it was -- 1.23;
rounding to any number of places works the same way. Rounding to 0 places is a "special case" where some steps are simplified away. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
Raknarg

|
Posted: Tue Nov 01, 2011 5:38 pm Post subject: RE:Superscript and Rounding Issues |
|
|
You could also use text manipulation. Convert it to a string, shorten it how you like and then convert it back into a decimal. |
|
|
|
|
 |
Tony

|
Posted: Tue Nov 01, 2011 5:55 pm Post subject: RE:Superscript and Rounding Issues |
|
|
Besides the performance hit, it simply seems like more work to track where in the string the decimal point is. String truncation would also act as floor(), not round(). |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
|
|