Lab: Repetition

Requirements

Modify the supplied program (repetitionLab.cpp) to make it work properly.

Program to be modified

/*
    repetitionLab.cpp
    Name: 
    CIS 150
    Date: 
    
    CIS 150 Chapter 5 Repetition Lab
*/

/*
    Place your name and section at the top in comments.
    Read the instructions for each section and then implement
    your solution within this program.

    You may comment out sections as you work. Declare variables
    if necessary. You do not need to get input from the user
    unless otherwise specified or that code is already written.
*/

#include <iomanip>
#include <iostream>
#include <cmath>
using namespace std;

int main() {
    cout << "Part 1 (while loop)\n";
    /* Part 1. Write a while loop that will output the square
       roots of the numbers from 10 to 20, each on it's own line.
    */

    cout << "\nPart 2 (do-while loop)\n";
    /* Part 2. Write a do-while loop that will output the square
       roots of the numbers from 10 to 20, each on it's own line.
    */

    cout << "\nPart 3 (for loop)\n";
    /* Part 3. Write a for loop that will output the square
       roots of the numbers from 10 to 20, each on it's own line.
    */

    cout << "\nPart 4 (input validation)\n";
    int num = -1;
    /* Part 4. Write a while loop around the following code that will
       validate that a user entered value is within the range 1 through 100
       by looping until the number the user entered is within that range.
    
    cout << "Enter a number between 1 and 100: ";
    cin >> num;
    */

    cout << "\nPart 5 (40 column table)\n";
    /* Part 5. Using ONE while or for loop, output the numbers from 1 to
       100. Each number should be in a field four characters wide and only
       ten numbers should display on a line. You will have to choose some
       way to output a newline after every tenth number.
       There are several different ways to count! 
         a. Create a counter variable. Add one to it each time you
            output an number. Using a decision structure, if you
            reach 10 output a newline and start your count over.
         or
         b. In a decision structure, use modulus to see if you have
            reached a number evenly divisible by 10
       Your output should look similar to this

         1   2   3   4   5   6   7   8   9  10
        11  12  13  14  15  16  17  18  19  20 
        21  22  23  24  25  26  27  28  29  30
        31  32  33  34  35  36  37  38  39  40
        41  42  43  44  45  46  47  48  49  50
        51  52  53  54  55  56  57  58  59  60
        61  62  63  64  65  66  67  68  69  70
        71  72  73  74  75  76  77  78  79  80
        81  82  83  84  85  86  87  88  89  90
        91  92  93  94  95  96  97  98  99 100
    */

    cin.ignore();
    cout << "Press enter to continue...";
    cin.get();

    return 0;
}

Example run of program

Part I (while loop)
The square root of 10 is 3.16228
The square root of 11 is 3.31662
The square root of 12 is 3.4641
The square root of 13 is 3.60555
The square root of 14 is 3.74166
The square root of 15 is 3.87298
The square root of 16 is 4
The square root of 17 is 4.12311
The square root of 18 is 4.24264
The square root of 19 is 4.3589
The square root of 20 is 4.47214

Part II (do-while loop)
The square root of 10 is 3.16228
The square root of 11 is 3.31662
The square root of 12 is 3.4641
The square root of 13 is 3.60555
The square root of 14 is 3.74166
The square root of 15 is 3.87298
The square root of 16 is 4
The square root of 17 is 4.12311
The square root of 18 is 4.24264
The square root of 19 is 4.3589
The square root of 20 is 4.47214

Part III (for loop)
The square root of 10 is 3.16228
The square root of 11 is 3.31662
The square root of 12 is 3.4641
The square root of 13 is 3.60555
The square root of 14 is 3.74166
The square root of 15 is 3.87298
The square root of 16 is 4
The square root of 17 is 4.12311
The square root of 18 is 4.24264
The square root of 19 is 4.3589
The square root of 20 is 4.47214

Part IV (input validation)
Enter a number between 1 and 100: -4
Enter a number between 1 and 100: 200
Enter a number between 1 and 100: 53

Part V (40 column table)
   1   2   3   4   5   6   7   8   9  10
  11  12  13  14  15  16  17  18  19  20
  21  22  23  24  25  26  27  28  29  30
  31  32  33  34  35  36  37  38  39  40
  41  42  43  44  45  46  47  48  49  50
  51  52  53  54  55  56  57  58  59  60
  61  62  63  64  65  66  67  68  69  70
  71  72  73  74  75  76  77  78  79  80
  81  82  83  84  85  86  87  88  89  90
  91  92  93  94  95  96  97  98  99 100
Press enter to continue...

Points (10 points total)