Tuesday, 25 August 2015

Write a program to convert the time from 24-hour notation to 12-hour notation and vice versa. Your program must be menu driven, giving the user the choice of converting the time between the two notations. Furthermore, your program must contain at least the following function: a function to convert the time from 24-hour notation to 12-hour notation, a function to convert the time from 12-hour notation to 24-hour notation, a function to display the choices, function(s) to get the input, and function(s) to display the results. (For 12-hour time notation, your program must display AM or PM.)

#include "stdafx.h"
#include<iostream>
using namespace std;
void input(int hours, int minutes, int seconds);
void convert(int hours, int ampm);
void output(int hours, int minutes, int seconds, int ampm);
void main ()
{
int hours, minutes ,seconds, ampm;
void input(int hours, int minutes, int seconds);
{
    cout << "Enter the hours"<<endl;
    cin >> hours;
    cout << "Enter the minute"<<endl;
    cin >> minutes;
cout << "Enter the second"<<endl;
cin >>seconds;
}
void convert(int hours, int ampm);
{
  if( hours < 12)
  {
      hours = hours + 12;
      minutes = minutes;
 seconds=seconds;
  }
  else if( hours > 12)
  {
      hours = hours-12 ;
      minutes = minutes;
 seconds = seconds;
     
  }
}
void output(int hours, int minutes, int ampm);
{
   if(ampm ='a')
   {
     cout << "The time in 12 hour is "<<hours<<":"<<minutes<<":"<<seconds<<"PM"<<endl;
   }
   else if(ampm ='p')
   {
  cout << "The time in 24 hour is "<<hours<<":"<<minutes<<":"<<seconds<<"AM"<<endl;
   }
}
system("pause");
}

1 comment: