INPUTS:
A user will enter a measurement.
The user will click a button to actuate the program.
OUTPUTS:
The number of sig figs in the measurement will be displayed.
CRITERIA & CONSTRAINTS:
Your program should have an impressive interface. (colors and graphics)
Your program should work if there is a decimal present or absent.
To code this program it will obviously be good for you to have a grasp of significant figures and especially how to count them in a given measurement. There are many sig fig counting rules especially when it comes to zeroes. We can eliminate all of those rules with one strategy that I call the Pacific-Atlantic method. You need to have a good understanding of this method to understand the helpful pseudocode that I have written for you below. Please first watch the following video and then you can use the pseudocode to build your program. Sorry, this first program is actually kind of challenging.
Create a function called sigfig( )
Create a variable called sheet to get the active sheet.
Create a variable called number and use the .getValue on the sheet to hold the value the user enters.
On the sheet format the number to be "plain text" instead of a number.
Create a Boolean variable called decimal_present and set it to false.
Create a variable called sigfigs and set it to 0.
Create a variable called decimal_location and set it to 0.
Create a Boolean variable called begin_counting and set it to false.
First, we will iterate through the number variable to see if one of the characters is a decimal. To do this, make a for loop from 0 to the length of number incrementing by 1.
In the for loop use an if statement to see if that character is a decimal: if (number[i]==".")
If a decimal is found set the decimal_present to true and set the decimal_location to i.
Set up an if (decimal_present) { } else { } statement and leave lots of room in the curly brackets. We will have to count differently depending on if the decimal is present or not.
In the first curly brackets, since the decimal_present is true we will need to count from the Pacific (left) side but not until we get to a character that is not a zero and not the decimal.
Again, make a for loop from 0 to the length of number incrementing by 1. (i++)
Inside the for loop make an if statement to check that the character is not a zero, not the decimal and the begin_counting variable is still false. Use && between all of these conditions. If they are all true then set begin_counting to true.
Make another if statement to check if begin_counting is true and the character is not the decimal point. This will look like: if(begin_counting && decimal_location!=i)
If both of those are true then add 1 to the sigfigs variable.
Now drop down to the else{ } where the decimal was not present. This time we need to count sig figs from the Atlantic (right) side so make a for loop from the length of number -1 down to i>=0 decrementing by 1. (i--)
Write an if statement to check that the character is not a 0 and begin_counting is still false.
If so, set begin_counting to true.
Write another if statement to see if begin_counting is true. If so, add 1 to the sigfigs variable.
In your last line of your function print the sigfigs variable back to your output box on your spreadsheet. Of course you will have this function run when a button is pressed on your spreadsheet interface.