The purpose of this assignment is to use the switch statement and nested loops.
Name your files hw3_<problem>.cpp, such as hw3_1.cpp. Email all the cpp files to my Sleipnir account.
switch
statement instead of the
if-else if-else
statement. Make sure your switch
statement contains a default statement to cover the case when the user selects
an unsupported menu option. You may alter the solution to Homework 2 Problem 2
instead of your code for that assignment if you wish.
for
loops to find all prime numbers
between 3 and 200. Recall from math that a number is prime if it is NOT evenly
divisible (remainder of division is 0) by any number other than itself and 1.
The outer loop will count from 3 to 200, keeping track of the number that you
are currently testing for "prime-ness". The inner loop will actually test if
a number is evenly divisible by numbers smaller than it (e.g. 2 to number-1
where number is the number you are testing for "prime-ness"). The modulo
operation (num1 % num2) will be useful here since it returns the remainder.
If the remainder is ever 0, the number is not a prime so you can skip it and
continue on to testing the next number. Output the number when it is a prime
(e.g. the inner loop tested all possible factors and the remainder was never
0). You may find Boolean flags useful for tracking "prime-ness" in the inner
loop.