The issue is that it doesn't seem as though the code isn't getting past the 3rd if-else statement, and even if the input is correct it will say invalid times and set the values to 0. I can't tell what the problem is.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
int startHr;
int startMin;
int stopHr;
int stopMin;
char colon;
char time1;
char time2;
int hours;
int min;
float rate;
float pay;
cout << "Time Clock Program" << '\n';
cout << "Enter worker name: ";
cin >> name;
cout << '\n';
cout << "Enter start time (hh:mm A/P): ";
cin >> startHr >> colon >> startMin >> time1;
cout << '\n';
cout << "Enter stop time (hh:mm A/P): ";
cin >> stopHr >> colon >> stopMin >> time2;
cout << '\n';
cout << "Enter pay rate: ";
cin >> rate;
cout << '\n';
if ( startHr > 12 || startHr <= 0 )
{
cout << "Invalid time! Time set to 0:00" << '\n';
cout << "Invalid time! Time set to 0:00" << '\n';
startHr = 0;
startMin = 00;
stopHr = 0;
stopMin = 00;
}
else if ( startMin > 59 || startMin < 0 )
{
cout << "Invalid time! Time set to 0:00" << '\n';
cout << "Invalid time! Time set to 0:00" << '\n';
startHr = 0;
startMin = 00;
stopHr = 0;
stopMin = 00;
}
else if ( time1 != 'p' || time1 != 'a' )
{
cout << "Invalid time! Time set to 0:00" << '\n';
cout << "Invalid time! Time set to 0:00" << '\n';
startHr = 0;
startMin = 00;
stopHr = 0;
stopMin = 00;
}
else if ( stopHr > 12 || stopHr < 0 )
{
cout << "Invalid time! Time set to 0:00" << '\n';
cout << "Invalid time! Time set to 0:00" << '\n';
startHr = 0;
startMin = 00;
stopHr = 0;
stopMin = 00;
}
else if ( stopMin > 59 || stopMin < 0 )
{
cout << "Invalid time! Time set to 0:00" << '\n';
cout << "Invalid time! Time set to 0:00" << '\n';
startHr = 0;
startMin = 00;
stopHr = 0;
stopMin = 00;
}
else if ( time2 != 'p' || time2 != 'a' )
{
cout << "Invalid time! Time set to 0:00" << '\n';
cout << "Invalid time! Time set to 0:00" << '\n';
startHr = 0;
startMin = 00;
stopHr = 0;
stopMin = 00;
}
else if ( time1 == 'p' && time2 == 'a' )
{
cout << "Invalid time! Time set to 0:00" << '\n';
cout << "Invalid time! Time set to 0:00" << '\n';
startHr = 0;
startMin = 00;
stopHr = 0;
stopMin = 00;
}
else if ( time1 == 'a' && time2 == 'a' )
{
if ( startHr <= stopHr )
{
if ( startMin <= stopMin )
{
cout << "Invalid time! Time set to 0:00" << '\n';
cout << "Invalid time! Time set to 0:00" << '\n';
startHr = 0;
startMin = 00;
stopHr = 0;
stopMin = 00;
}
else;
}
else;
}
system ("pause");
return 0;
}