Untitled
unknown
c_cpp
3 years ago
2.8 kB
3
Indexable
// BT.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include <iostream> #include <string> using namespace std; //TODO CHECK IS VALID VALUE bool isNumeric(string str) { for (int i = 0; i < str.length(); i++) if (isdigit(str[i]) == false) return false; //when one non numeric value is found, return false return true; } //CONVERT SECOND TO TIME void convertSecondToTime(int s) { int h = 0, m = 0, ss =0; if (s < 60) { cout << "RESULT: "; cout << s << "s"; } else if (s >= 60 && s < 3600) { m = (s - s % 60) / 60; // BT.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include <iostream> #include <string> using namespace std; //TODO CHECK IS VALID VALUE bool isNumeric(string str) { for (int i = 0; i < str.length(); i++) if (isdigit(str[i]) == false) return false; //when one non numeric value is found, return false return true; } //CONVERT SECOND TO TIME void convertSecondToTime(int s) { int h = 0, m = 0, ss =0; if (s < 60) { cout << "RESULT: "; cout << s << "s"; } else if (s >= 60 && s < 3600) { m = (s - s % 60) / 60; ss = s % 60; cout << "RESULT: "; cout << m << "m " << ss << "s"; } else { h = (s - s % 3600) / 3600; m = ((s%3600) - (s%3600)%60 ) / 60 ; ss = s - m * 60 - h * 3600; cout << "RESULT: "; cout << h<<"h " << m << "m " << ss << "s"; } } int main() { string iSecond = "0"; int n; char tt; do { cout << "Input Second: "; cin >> iSecond; if (!isNumeric(iSecond)) cout << "Wrong type!!!"; else { int num = stoi(iSecond); convertSecondToTime(num); } cout << "\n Press y or Y to continue, press any key to exit. "; cin >> tt; } while (tt == 'y' || tt == 'Y'); } ss = s % 60; cout << "RESULT: "; cout << m << "m " << ss << "s"; } else { h = (s - s % 3600) / 3600; m = ((s%3600) - (s%3600)%60 ) / 60 ; ss = s - m * 60 - h * 3600; cout << "RESULT: "; cout << h<<"h " << m << "m " << ss << "s"; } } int main() { string iSecond = "0"; int n; char tt; do { cout << "Input Second: "; cin >> iSecond; if (!isNumeric(iSecond)) cout << "Wrong type!!!"; else { int num = stoi(iSecond); convertSecondToTime(num); } cout << "\n Press y or Y to continue, press any key to exit. "; cin >> tt; } while (tt == 'y' || tt == 'Y'); }
Editor is loading...