Schedule‎ > ‎

blink.cpp

   CS-11 blink.cpp
    Purpose: blink a light on and off.

    @author Sharon Strelitz
    @version 1.0 2/07/18
*/
#include <iostream>
using namespace std;
#include <chrono>
#include <thread>

const int MAX_BLINKS = 5;
const int ON = true;
const int OFF = false;

int main() {
    char response = 'y';
    while ('y' == response)  {
       cout << "do you want to turn the light off and on? (y/n) ";
       cin >> response;
       if ('y' == response)  {
           for (int i = 0; i < MAX_BLINKS; i++) {
               cout << "Light turned ON!" << endl;
               std::this_thread::sleep_for(std::chrono::milliseconds(500));  //1000 ms is 1 second
               cout << "Light turned OFF!"  << endl;
            }
        }
    }
}
Comments