By the end of this module, for simple programs with real numbers, you will be able to:
Just like we did with integers, we can declare variables and assign values to them:
Another example:
Again, as with integers, the standard operators apply:
In-Class Exercise 1: Write a program to print out the area of a circle whose radius is 1.5 inches.
In-Class Exercise 2: Can you find a well-known formula or law in science or engineering that uses all four of the standard operators: +, -, *, /? If not, find one that uses as many as possible.
In-Class Exercise 3: Do the increment and decrement operators work with real numbers?
Now consider this simple example:
In-Class Exercise 4: Change the assignment to:
and see what prints. Explain the result.
Consider the following program:
In-Class Exercise 5: What you suppose will be printed? Try it. Then, change the program so that you initially assign the value of 1 to i and then assign i to x.
An assignment from an int to a double works fine:
About casting:
In-Class Exercise 6: What do you get when you cast the real value 0.5 to an int?