My code is supposed to convert military time to standard time.
I need to restrict the user from entering hour>25 and less than 0, and minute>59 and less than 0.
Here's what I got so far.
#include <iostream>
using namespace std;
void get_input_24hou rs ( int & hour24,char & colon, int & minute24);
void convert_24_to_a mOrPM ( int & hour24, int & houramOrPM, int & minute24, char & amOrPM);
void output(int & houramOrPM, char & colon, int & minute24, char & amOrPM);
void main ()
{
int hour24, minute24, houramOrPM;
char amOrPM, colon, ans='y';
do{
get_input_24hou rs ( hour24, colon, minute24);
convert_24_to_a mOrPM ( hour24, houramOrPM, minute24, amOrPM );
output ( houramOrPM, colon, minute24, amOrPM);
cout<<"\nWould you like to check it again?\n"
<<"\nDo you want to go again?(Y/N):\n";
cin>>ans;
}while ( ans=='y'|| ans=='Y');
cout<<"\nGood-bye"<<endl;
}
void get_input_24hou rs (int & hour24, char & colon, int & minute24)
{
cout<<"\nEnter the time using the following format(hour:min ute24)";
cin>>hour24>>co lon>>minute24;
}
void convert_24_to_a mOrPM( int & hour24, int & houramOrPM, int & minute24, char & amOrPM)
{
if ((hour24>=0)&&( hour24<=12))
{
houramOrPM= hour24;
amOrPM='A';
}
if ((hour24>=12)&& (hour24<=23)&&( minute24>=0)&&( minute24<=59))
{
houramOrPM=hour 24-12;
amOrPM='P';
}
if((hour24>=0)& &(hour24<1)&&(m inute24>=0)&&(m inute24<=59))
{
houramOrPM=12;
amOrPM= 'A';
}
if (hour24==12)
{
houramOrPM=12;
amOrPM='P';
}
}
void output(int & houramOrPM, char & colon, int & minute24, char & amOrPM)
{
cout<<"\nThe time in twelve hour notation is: " <<houramOrPM<<c olon<<minute24< <amOrPM<<"M"<<e ndl;
}
please help
I need to restrict the user from entering hour>25 and less than 0, and minute>59 and less than 0.
Here's what I got so far.
#include <iostream>
using namespace std;
void get_input_24hou rs ( int & hour24,char & colon, int & minute24);
void convert_24_to_a mOrPM ( int & hour24, int & houramOrPM, int & minute24, char & amOrPM);
void output(int & houramOrPM, char & colon, int & minute24, char & amOrPM);
void main ()
{
int hour24, minute24, houramOrPM;
char amOrPM, colon, ans='y';
do{
get_input_24hou rs ( hour24, colon, minute24);
convert_24_to_a mOrPM ( hour24, houramOrPM, minute24, amOrPM );
output ( houramOrPM, colon, minute24, amOrPM);
cout<<"\nWould you like to check it again?\n"
<<"\nDo you want to go again?(Y/N):\n";
cin>>ans;
}while ( ans=='y'|| ans=='Y');
cout<<"\nGood-bye"<<endl;
}
void get_input_24hou rs (int & hour24, char & colon, int & minute24)
{
cout<<"\nEnter the time using the following format(hour:min ute24)";
cin>>hour24>>co lon>>minute24;
}
void convert_24_to_a mOrPM( int & hour24, int & houramOrPM, int & minute24, char & amOrPM)
{
if ((hour24>=0)&&( hour24<=12))
{
houramOrPM= hour24;
amOrPM='A';
}
if ((hour24>=12)&& (hour24<=23)&&( minute24>=0)&&( minute24<=59))
{
houramOrPM=hour 24-12;
amOrPM='P';
}
if((hour24>=0)& &(hour24<1)&&(m inute24>=0)&&(m inute24<=59))
{
houramOrPM=12;
amOrPM= 'A';
}
if (hour24==12)
{
houramOrPM=12;
amOrPM='P';
}
}
void output(int & houramOrPM, char & colon, int & minute24, char & amOrPM)
{
cout<<"\nThe time in twelve hour notation is: " <<houramOrPM<<c olon<<minute24< <amOrPM<<"M"<<e ndl;
}
please help
Comment