CSCI 102 - Fall 2023 Fundamentals of Computation

Week 5 Lab

Sign in to lab!

Q&A on Material

Tracing

Trace the execution of this program and predict what this program will output when the users types in 3. Then repeat the exercise if the user types in 9.

#include <iostream>
#include <cmath>
using namespace std;
int main() 
{
    int i;
    char color = 'r'; 
    cin >> i;

    if (i % 5 != 0) 
    {
        i++;
        color = 'b';
    }
    if (i % 5 == 0) 
    {
        i -= 2;
    } 
    else if (i % 4 == 0) 
    {
        i++;
        if ((color == 'r') || (i == 9)) 
        {
            color='c';
        }
    }
    else 
    {
        i += 5;
        color='g';
    }
    return 0;
}

Take a look at the idioms related to if (conditional) statements:

Exercises

Walk through these exercises and complete them as a group. Identify what idiom is most appropriate for each exercise.

cpp/cs102/practice6/tippingCalculator
cpp/cs102/decision-tree/menu
cpp/cs102/lookup-table/sales-tax

HW05 Review

Q&A on Material

Open time to get help on HW05 or any other material.