Lab: Selection

Requirements

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

Program to be modified

/*
    decisionsLab.cpp
    Name: 
    CIS 150
    Date: 
    
    CIS 150 Chapter 4 Decisions Lab
*/

/*
    Place your name and section at the top in comments.
    Read the instructions for each question and give your
    answer in comments or write the code into the 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 <cstdio>
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
    cout << "Part 1\n";
    for (int age=50; age<=80; age=age+15) {
        cout << "Testing with age = " << age << '\n';
        float admission = 0.0;
        
        /* Part 1. Find and fix the error(s) in the following code.
        if (age > = 65);
            cout <<"Age greater than or equal to 65\n";
            admission = 10.0;
        else
            cout << "Age is less than 65\n";
            admission = 15.0;
        cout << "Admission: " << fixed << showpoint << setprecision(2) << admission << '\n';
        */
    }

    cout << "\nPart 2\n";
    for (int count=5; count<=15; count+=5) {
        cout << "Testing with count = " << count << '\n';
        /* Part 2. Find and fix the error(s) in the following code.
        if (count = 10) cout << "The count is 10\n";
        else cout << "The count is NOT 10\n";
        */
    }

    cout << "\nPart 3\n";
    for (int score=-50; score<=150; score+=50) {
        cout << "Testing with score = " << score << '\n';
        /* Part 3. Find and fix the error(s) in the following code.
        
        // checking to see of score is less than 0 or greater than 100
        if (0 > score > 100) cout << "The score is out of range\n";
        else cout << "The score is in range\n";
        */
    }

    cout << "\nPart 4\n";
    cout << "1. Enter data and save to file\n"
         << "2. Read data in and display report\n"
         << "3. Quit the program\n";
    for (int option=-1; option<=4; option++) {
        cout << "Testing with option = " << option << '\n';

        /* Part 4. Write a switch statement that will display a simple message
           telling the user which option was chosen. For example, if the option
           chosen was 2, output "Read data". Display an invalid entry message if
           the option chosen is something other than 1, 2, or 3. For testing
           purposes the option will be chosen by a loop variable rather than
           getting actual user input.
        */
    }

    cout << "\nPart 5\n";
    for (double sales=0.0; sales<=25000.0; sales+=2500.0) {
        cout << "Testing with sales = $" << fixed << showpoint << setprecision(2) << sales << '\n';
        double rate = 0.0;
        
        /* Part 5. Write a decision structure that will set the variable rate
           to the proper value based on the value of sales. Follow these rules:
            No commision is paid for sales of 0 or less.
            A sales commision of 2% (.02) is paid for sales over 0 up to 10,000.
            A sales commision of 3% (.03) is paid for sales over 10,000 up to 15,000.
            A sales commision of 4% (.04) is paid for sales over 15,000 up to 20,000.
            A sales commision of 5% (.05) is paid for sales over 20,000.
        
        // write your code to set the rate here
        
        cout << "The commission is $" << rate * sales << endl;
        
        */
    }

    // cross platform pause
    if (cin.rdbuf()->sungetc() != -1 && cin.get() != '\n') cin.ignore(80,'\n');
    cout << "Press enter to continue...";
    cin.get();

    return 0;
}

Example run of program

Part 1
Testing with age = 50
Age is less than 65
Admission: 15.00
Testing with age = 65
Age greater than or equal to 65
Admission: 10.00
Testing with age = 80
Age greater than or equal to 65
Admission: 10.00

Part 2
Testing with count = 5
The count is NOT 10
Testing with count = 10
The count is 10
Testing with count = 15
The count is NOT 10

Part 3
Testing with score = -50
The score is out of range
Testing with score = 0
The score is in range
Testing with score = 50
The score is in range
Testing with score = 100
The score is in range
Testing with score = 150
The score is out of range

Part 4
1. Enter data and save to file
2. Read data in and display report
3. Quit the program
Testing with option = -1
Invalid choice
Testing with option = 0
Invalid choice
Testing with option = 1
Enter data
Testing with option = 2
Read data
Testing with option = 3
Quit
Testing with option = 4
Invalid choice

Part 5
Testing with sales = $0.00
The commission is $0.00
Testing with sales = $2500.00
The commission is $50.00
Testing with sales = $5000.00
The commission is $100.00
Testing with sales = $7500.00
The commission is $150.00
Testing with sales = $10000.00
The commission is $200.00
Testing with sales = $12500.00
The commission is $375.00
Testing with sales = $15000.00
The commission is $450.00
Testing with sales = $17500.00
The commission is $700.00
Testing with sales = $20000.00
The commission is $800.00
Testing with sales = $22500.00
The commission is $1125.00
Testing with sales = $25000.00
The commission is $1250.00
Press enter to continue...

Points (10 points total)