Как сделать проверку для 3-х переменных на то, что бы это был ввод только чисел? Code:
// hms_to_secs.cpp
// convert hour, minuts, second to seconds
// input for example: 23 59 59
// output: 86399
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
/////////////////////////////////////////////////////////////////////////////////////////////////
long hms_to_secs(int&, int&, int&); // prototype
/////////////////////////////////////////////////////////////////////////////////////////////////
int main()
{
int h, m, s; // hour, minute, second
while (true)
{
cout << "Enter (hours minuts seconds): " << endl;
cin >> h >> m >> s;
for (int x = 0; x < 50; ++x) cout << "~";
cout << endl;
cout << "Result: " << hms_to_secs(h, m, s) << " seconds" << endl << endl;
for (int x = 0; x < 50; ++x) cout << "~";
cout << endl;
}
return false;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
long hms_to_secs(int& hours, int& minuts, int& second)
{
unsigned long sec;
sec = (hours * 3600) + (minuts * 60) + second;
cout << "Addres of hours: " << &hours << "[value: " << *(&hours) << "]"
<< "\nAddres of minuts: " << &minuts << "[value: " << *(&minuts) << "]"
<< "\nAddres of second: " << &second << "[value: " << *(&second) << "]";
cout << "\n\n\nSIZE OF SEC: " << sizeof(sec) << endl;
return sec;
}