Solution: Smart Home Mode Selector
Explore how to use the switch statement to select modes in a smart home system programmatically. Understand branching for various mode IDs and how to handle unexpected inputs effectively within C++ control flow.
We'll cover the following...
We'll cover the following...
#include <iostream>
int main() {
int modeID;
std::cout << "Please enter a modeID: ";
std::cin >> modeID;
// Implementation of the switch statement
switch (modeID) {
case 1:
std::cout << "Smart Home set to: Home Mode" << std::endl;
break; // Exits the switch block
case 2:
std::cout << "Smart Home set to: Away Mode" << std::endl;
break; // Exits the switch block
case 3:
std::cout << "Smart Home set to: Night Mode" << std::endl;
break; // Exits the switch block
default:
std::cout << "Invalid modeID. Please select 1, 2, or 3." << std::endl;
break;
}
return 0;
}Boilerplate code for the smart home mode selector
...