function ...!
Nov 26, 2011 at 9:59pm UTC
hi people ...
anyone can help me to devide this code into one function or more i couldnt do it i tried for 3hr
i will use this function to make sure that the user input the time as HH:MM:SS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
bool isValidTime(int , int , int );
const char delim = ':' ;
int main() { string in;
stringstream ss;
char c1, c2;
int hr, min, sec;
cout << "Enter HH:MM:SS : " << endl;
while (true ) {
cout << "> " ;
getline(cin,in);
ss.clear(); ss.str(in);
if ((ss >> hr >> c1 >> min >> c2 >> sec) &&
(c1 == delim) && (c1 == c2) &&
isValidTime(hr, min, sec)) {
cout << "ok" << endl;
} else {
cout << "invalid time" << endl;
}
}
Last edited on Nov 27, 2011 at 1:08pm UTC
Nov 27, 2011 at 1:08pm UTC
?????
Topic archived. No new replies allowed.