I have a program that needs comments added to it: #include <iostream> #include <
ID: 3687142 • Letter: I
Question
I have a program that needs comments added to it:
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <windows.h>
using namespace std;
int main()
{
int m, s,h;
cout << "A COUNTDOWN TIMER " << endl;
cout << "enter time in hours here" << endl;
cin >> h;
cout << "enter time in minutes here " << endl;
cin >> m;
cout << "enter time in seconds here" << endl;
cin >> s;
cout << "Press any key to start" << endl;
cout << " A COUNTDOWN TIMER" << endl;
cout << "time remaining" << endl;
cout << "hours : " << h << "mins : " << m << " secs : " << s << endl;
for (int hour = h; hour >= 0; hour--)
{
for (int min = m; min >= 0 ; min--)
{
if ( min == 0 && h > 0)
m = 59;
for (int sec = s; sec >= 0; sec--)
{
if ( sec == 0 )
s = 59;
Sleep(1000);
system("clear");
cout << hour << " :hours " << min << " :mins " << sec << " :secs" << endl;
}
}
}
Sleep(1000);
cout << "THE END" << endl;
return 0;
}
Explanation / Answer
//include the required directives
#include<iostream>
#include<thread>
#include<chrono>
#include<conio.h>
using namespace std;
//Start of main
int main()
{
//declare variables
int m, s,h;
//input the required details like hours,miin,sec
cout << "A COUNTDOWN TIMER " << endl;
cout << "enter time in hours here" << endl;
cin >> h;
cout << "enter time in minutes here " << endl;
cin >> m;
cout << "enter time in seconds here" << endl;
cin >> s;
cout << "Press any key to start" << endl;
//timer starts after inputiing the details
cout << " A COUNTDOWN TIMER" << endl;
cout << "time remaining" << endl;
//diaplasy the inital time
cout << "hours : " << h << "mins : " << m << " secs : " << s << endl;
//timer starts decreasing until reached 0
for (int hour = h; hour >= 0; hour--)
{
for (int min = m; min >= 0 ; min--)
{
if ( min == 0 && h > 0)
m = 59;
for (int sec = s; sec >= 0; sec--)
{
if ( sec == 0 )
s = 59;
Sleep(1000);
system("clear");
cout << hour << " :hours " << min << " :mins " << sec << " :secs" << endl;
}
}
}
Sleep(1000);
cout << "THE END" << endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.