Code:
#include <iostream>
using namespace std;
string Time;
int main()
{
while ( EOF )
{
system( "cls" );
cout<< "Enter the Time in hour:minuts here: ";
cin>> Time;
cout<< endl;
if ( Time.length() == 5 )
{
if ( Time.substr( 0, 1 ) == "0" || Time.substr( 0, 1 ) == "1" )
{
if ( Time.substr( 1, 1 ) == "0" || Time.substr( 1, 1 ) == "1" || Time.substr( 1, 1 ) == "2" ||
Time.substr( 1, 1 ) == "3" || Time.substr( 1, 1 ) == "4" || Time.substr( 1, 1 ) == "5" ||
Time.substr( 1, 1 ) == "6" || Time.substr( 1, 1 ) == "7" || Time.substr( 1, 1 ) == "8" ||
Time.substr( 1, 1 ) == "9" )
{
if ( Time.substr( 2, 1 ) == ":" )
{
if ( Time.substr( 3, 1 ) == "0" || Time.substr( 3, 1 ) == "1" || Time.substr( 3, 1 ) == "2" ||
Time.substr( 3, 1 ) == "3" || Time.substr( 3, 1 ) == "4" || Time.substr( 3, 1 ) == "5" )
{
if ( Time.substr( 4, 1 ) == "0" || Time.substr( 4, 1 ) == "1" || Time.substr( 4, 1 ) == "2" ||
Time.substr( 4, 1 ) == "3" || Time.substr( 4, 1 ) == "4" || Time.substr( 4, 1 ) == "5" ||
Time.substr( 4, 1 ) == "6" || Time.substr( 4, 1 ) == "7" || Time.substr( 4, 1 ) == "8" ||
Time.substr( 4, 1 ) == "9" )
{
cout<< "Correct Time: "<< Time<< endl;
cin.get();
cin.get();
}
else
{
cout<< "Incorrect Time: "<< Time<< endl;
cout<< endl;
cout<< "ERROR: The 5th Array: "<< Time[4]<< endl;
cin.get();
cin.get();
}
}
else
{
cout<< "Incorrect Time: "<< Time<< endl;
cout<< endl;
cout<< "ERROR: The 4th Array: "<< Time[3]<< endl;
cin.get();
cin.get();
}
}
else
{
cout<< "Incorrect Time: "<< Time<< endl;
cout<< endl;
cout<< "ERROR: The 3rd Array: "<< Time[2]<< endl;
cin.get();
cin.get();
}
}
else
{
cout<< "Incorrect Time: "<< Time<< endl;
cout<< endl;
cout<< "ERROR: The 2nd Array: "<< Time[1]<< endl;
cin.get();
cin.get();
}
}
else if ( Time.substr( 0, 1 ) == "2" )
{
if ( Time.substr( 1, 1 ) == "0" || Time.substr( 1, 1 ) == "1" || Time.substr( 1, 1 ) == "2" ||
Time.substr( 1, 1 ) == "3" )
{
if ( Time.substr( 2, 1 ) == ":" )
{
if ( Time.substr( 3, 1 ) == "0" || Time.substr( 3, 1 ) == "1" || Time.substr( 3, 1 ) == "2" ||
Time.substr( 3, 1 ) == "3" || Time.substr( 3, 1 ) == "4" || Time.substr( 3, 1 ) == "5" )
{
if ( Time.substr( 4, 1 ) == "0" || Time.substr( 4, 1 ) == "1" || Time.substr( 4, 1 ) == "2" ||
Time.substr( 4, 1 ) == "3" || Time.substr( 4, 1 ) == "4" || Time.substr( 4, 1 ) == "5" ||
Time.substr( 4, 1 ) == "6" || Time.substr( 4, 1 ) == "7" || Time.substr( 4, 1 ) == "8" ||
Time.substr( 4, 1 ) == "9" )
{
cout<< "Correct Time: "<< Time<< endl;
cin.get();
cin.get();
}
else
{
cout<< "Incorrect Time: "<< Time<< endl;
cout<< endl;
cout<< "ERROR: The 5th Array: "<< Time[4]<< endl;
cin.get();
cin.get();
}
}
else
{
cout<< "Incorrect Time: "<< Time<< endl;
cout<< endl;
cout<< "ERROR: The 4th Array: "<< Time[3]<< endl;
cin.get();
cin.get();
}
}
else
{
cout<< "Incorrect Time: "<< Time<< endl;
cout<< endl;
cout<< "ERROR: The 3rd Array: "<< Time[2]<< endl;
cin.get();
cin.get();
}
}
else
{
cout<< "Incorrect Time: "<< Time<< endl;
cout<< endl;
cout<< "ERROR: The 2nd Array: "<< Time[1]<< endl;
cin.get();
cin.get();
}
}
else
{
cout<< "Incorrect Time: "<< Time<< endl;
cout<< endl;
cout<< "ERROR: The 1st Array: "<< Time[0]<< endl;
cin.get();
cin.get();
}
}
else
{
cout<< "Incorrect Time: "<< Time<< endl;
cout<< endl;
cout<< "ERROR: The Size isn't correct: "<< Time.length()<< endl;
cin.get();
cin.get();
}
}
}