Nov 10, 2016 at 8:04pm UTC
1 #include <iostream>
2 #include <windows.h>
3 using namespace std;
4
5 int main()
6 {
7 int seconds, hours, minutes, timeinsec;
8 char colon;
9
10 cout << "Enter Time (format 12:59:59)"<< endl;
11 cout << "(0:0:0 to quit):";cin>> hours >> colon>> minutes>> colon >> seconds;
12
13
14 cout << endl;
15
16 timeinsec =(hours * 3600 ) + (minutes * 60) + seconds;
17
18 cout << "seconds = " << timeinsec << endl<<endl;
19
20
21
22
23 string password;
24
25 cout <<"(0:0:0 to quit)" << endl;
26 getline (cin,password,'\n');
27
28 if (password == "0:0:0")
29 {
30 quit(0);
31
32 }
33
34
36
37 return 0;
38 }
39
how can I make this function quit after the user is prompted to writes 0:0:0
please anyone know?
what I mean is I need for it to just close(terminate) automatically after the user wrote 0:0:0
thanks for the help
Last edited on Nov 11, 2016 at 3:36pm UTC
Nov 11, 2016 at 4:19am UTC
none of these worked because first of all it didn't even let me type the password and as soon as I typed the first 0 the program disappeared:(
I want the program to disappear once I type the password 0:0:0
Nov 11, 2016 at 4:20am UTC
thanks for trying to help thought
Nov 11, 2016 at 4:20am UTC
dos anyone please know how to actually make this work
Nov 11, 2016 at 10:02am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#include <iostream>
using namespace std;
int main()
{
int seconds = 0, hours = 0, minutes = 0, timeinsec = 0;
char colon = ':' ;
cout << "Enter Time (format 12:59:59) (0:0:0 to quit): " ;
while ( cin >> hours >> colon >> minutes >> colon >> seconds )
{
timeinsec = ( hours * 3600 ) + ( minutes * 60 ) + seconds;
if (timeinsec == 0)
break ;
else
cout << "seconds = " << timeinsec << endl;
}
cout << "Program ends\n" ;
return 0;
}
Last edited on Nov 11, 2016 at 10:03am UTC
Nov 11, 2016 at 3:31pm UTC
what I'm looking for is for the program to terminate after I write 0:0:0
not for it to display program end
thanks for trying thought but I need it to exit automatically once I type 0:0:0
Nov 11, 2016 at 4:29pm UTC
but it still the program wont exit once I type 0:0:0
Nov 11, 2016 at 4:31pm UTC
I really need help I don't know what else to do to make it do that
Nov 11, 2016 at 4:51pm UTC
What is the current code you're trying to run?
Nov 11, 2016 at 5:26pm UTC
23 string password;
24
25 cout <<"(0:0:0 to quit)" << endl;
26 getline (cin,password,'\n');
27
28 if (password == "0:0:0")
29 {
30 quit(0);
31
32 }
33
34
36
37 return 0;
38 }
Nov 11, 2016 at 5:29pm UTC
I don't know if its correct but the idea is to type 0:0:0 then the program just gos away in other words exit automatically after I type 0:0:0
Nov 11, 2016 at 5:48pm UTC
Did you try Kemort's code above, without the line 22 printing out the program end message? It seems to do what you're trying to accomplish.
Nov 11, 2016 at 5:49pm UTC
If the program I wrote still does not exit then try turning the power off or setting fire to your computer. Sometimes that happens with these complex operating systems and unfortunately that's all you can do.
If that doesn't work send me your computer by courier and I will do it for you. Make sure you send money for the return postage.
Nov 11, 2016 at 5:56pm UTC
I did try with out line 22 but it dosent exit by itself it waits for me to press enter
Nov 11, 2016 at 5:57pm UTC
I cant send my computer need it for school
but what do you mean by set fire to computer
Nov 11, 2016 at 6:08pm UTC
Pour petrol on it, strike a match, then kaboom. That should make an effective exit.