Variable Answers

Answers to Variable Recap II:

Answers to the questions on the recap page appear below in italics.

1. Is a value of 1 considered an integer, float or character? What about a value of 1.0?

A value of 1 is an integer type variable but it can be stored in a float variable as well as an integer. A value of 1.0 is a float type variable but it can be stored in an integer variable as well as a float- if stored in an integer variable the value of 1.0 will turn into a value of 1.

2. Which of the three array types (integer, float and character) could you use to store the following sets of information?

  • a r c b o t i c s

The data above needs a character array

  • 1 7 8 16 4 368 0 -2 18 -6531 7 5 82

The data above needs an integer array- it will also fit in a float array but .0 will be tacked onto the end of each variable value.

  • 4 7.3 456.3 e 7 154 56 -12.6 54 u 1212.3333 567 – 6832.1

This data will not fit into an array.

  • .3 0.0 6.4 -4.6 6.7 4.3333 4.001 .6 -104.0 12012.11118 8.0

The data above needs a float array. You can put these values into an integer array but the computer will throw away the decimal points and any data after the decimal points resulting in different values.

3. Is it possible to store two different pieces of information in a single variable at the same time?

No, it is not possible to store two different pieces of information in a single variable at the same time.

4. How about using two different variables to get more than two pieces of information about those two variables? (Hint, you can’t do this with character variables.)

Using two number variables (two floats, two integers or a combination of a float and an integer) you can store two numbers and then subtract one from the other to find the difference between the numbers or add them together to find the sum of the two numbers.

Back to the Variables Recap II