Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
wiki:ideas:teaching [2010/04/22 12:58] – jeff | wiki:ideas:teaching [2020/11/19 14:21] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Teaching C++ ====== | ====== Teaching C++ ====== | ||
+ | |||
+ | [[http:// | ||
main.cpp | main.cpp | ||
Line 23: | Line 25: | ||
===== Practice ===== | ===== Practice ===== | ||
- | Compute the range of the projectile. | + | ==== Test 1 ==== |
+ | |||
+ | Compute the range of the projectile. | ||
< | < | ||
+ | #include < | ||
+ | |||
angleR = angleD * Pi / 180.0; | angleR = angleD * Pi / 180.0; | ||
range = sin(2.0 * angleR) * pow(velocity, | range = sin(2.0 * angleR) * pow(velocity, | ||
+ | </ | ||
+ | |||
+ | ==== Test 2 ==== | ||
+ | |||
+ | Guess a number between 1 and 100. First generate a random value between 1 and 100. Have the user enter a number that is between 1 and 100. Then create a function that will check if the number is to high, to low, or is the correct number. | ||
+ | |||
+ | < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | /* initialize random seed: */ | ||
+ | srand( time(NULL) ); | ||
+ | |||
+ | /* generate secret number: */ | ||
+ | randomValue = rand() % 10 + 1; | ||
</ | </ |