Hello. So I was messing around trying to make a shutdown timer for my computer. I want to have a way to stop it if I need, and the method I use doesn't really do that.I want the while loop I use to keep running and stop when I enter a certain text. I would appreciate any help :D .
#include <iostream>
#include <stdlib.h>
usingnamespace std;
int main()
{
int timer, hours, minutes, seconds;
string stop;
system("echo off");
system("color 0F");
system("CLS");
label:
cout<<" Automatic shutdown in : (h/m/s) "<<'\n';
cin>>hours;
cin>>minutes;
cin>>seconds;
cout<<" Computer will shutdown in "<<hours<<" hour(s), "<<minutes<<" minute(s) and "<<seconds<<" second(s)."<<'\n';
timer=seconds+minutes*60+hours*3600;
while (timer) // i want this while to keep running, not waiting for me to type something and then timer--
{
cin>>stop;
if ((stop=="stop")||(stop=="STOP")) break;
else timer--;
}
string s1, s2; // didn't know how to use goto along with the system("pause>nul") command so I kinda improvised
if (timer==0) system("shutdown /s /f /t 1");
else cout<<" Press any key to return to Shutdown timer input "<<'\n';
cin>>s1;
if (s1!=s2) goto label;
return 0;
}
Thank you guys for the help, I really appreciate it. I don't understand more than 15% of MiiNiPaa's code :s. The thing is I'm new to this, our class only learn how to use cin, cout, a little bit of <fstream> library, <cmath> library, for loop, while loop and that's kinda it. I am a bit ahead because i like c++ but I still don't know what I'm doing :d.