Many programs need nested loops, process inputs, or are simulations.
Two or more dimensions.
Informal example
while(not full)
{
while(some ice cream left)
eat a spoonful;
get some more ice cream;
}//end while not full
Examples of Nested loops
ch03/
[ triangle.cpp ]
(pages 132-133).
Wall Paper:
[ wp.cpp ]
[ wp.png ]
Good advice for reading data from the user.
Study this now.
Here is a quick example of loop-and-a-half:
[ 08loop.cpp ]
Here we want to read until the user inputs a something that
is not a number or is a smaller number.
Neat trick that works in Linux, MacOs, and MSWindows. Learn it!
The first loop is a very simple and powerful way to process all the input data.
Be ready to use it.
Later. But note -- after you discover cin.fail() is true with an if
you must (1) handle the failure (think), and (2) clear the state of cin with cin.clear()
before doing anything else with cin.
Just for fun... try
[ watch?v=xx8f4x6C_KY ]
(YouTube, 2:28 mins)
and then you can go to
[ ?page_id=2086 ]
which analyses why this system failed.
We will simulate somethings in the lab this quarter.
Here is an improved version of
[ buffon.cpp ]
from pages 141-143.
Here
[ piman.cpp ]
is a simpler attempt at finding π by thowing
darts at a square board and counting how many are inside part of a circle.