HELP PLEASE

May 8, 2016 at 2:40pm
I am supposed to rite a program that convert the time from 24-hour notation to 12-hour notation and vice versa. My program must be menu driven, giving the user the choice of converting the time between the two notations. Furthermore, my program must contain at least the following function:
i. function(s) to get the input, (hint: use pass-by-reference)
ii. a function to convert the time from 24-hour notation to 12-hour notation,
iii.a function to convert the time from 12-hour notation to 24-hour notation,
iv. function(s) to display the results.

but it is not building here is the code


#include <iostream>
int hour, minute, second, hours;
char type;
using namespace std;

void input1(int& hours, int& minute, int& second);
void input2(int& hours, int& minute, int& second);
void convert12to24(int& hour, char& type);
void convert24to12(int& hour, char& type);
void output (int hour, int minute, char type);

int main()
{
int choice;
cout<< "Enter --"<< endl;
cout<< "1: To convert time from 12-hours notation."<< endl;
cout<< "2: To convert time from 24-hours notation."<< endl;
cout<< "99: To quite the program."<< endl;
cin>> choice;

if (choice == 2)
{
input1(hours, minute, second);
convert12to24( hour, type);
cout<< "The time is \t"<< hour << ":"<< minute<< ":"<< second<< " "<< type<< "M"<< endl;

}

else if (choice == 1)
{
input2(hours, minute, second);
convert24to12(hour, type);
cout<< "The time is \t"<< hour << ":"<< minute<< ":"<< second<< " "<< type<< "M"<< endl;
}

else
cout<< "Goodbye";



return 0;
}

void input1(int& hours, int& minute, int& second)
{
cout<<endl<< "Enter hours: ";
cin>> hours;
cout<< endl;

cout<< endl<< "Enter minutes: ";
cin>> minute;
cout<< endl;

cout<< endl<< "Enter seconds: ";
cin>> second;
cout<< endl<< endl;

}

void convert24to12(int& hour, char& type)
{
input1(hours, minute, second);
if (hour > 12)
{
hour= hour -12;
minute= minute;
second= second;
type= 'A';
}
else
{
hour=hour;
minute= minute;
second= second;
type= 'P';
}

}

void input2(int& hours, int& minute, int& second, char& type)
{
cout<<endl<< "Enter hours: ";
cin>> hours;
cout<< endl;

cout<< endl<< "Enter minutes: ";
cin>> minute;
cout<< endl;

cout<< endl<< "Enter seconds: ";
cin>> second;
cout<< endl;

cout<<endl<< "Enter PM/AM: ";
cin>> type;
cout<<"m"<< endl;

}


void convert12to24(int& hour, char& type)
{
if (type == 'a')
hour= hours +12;
else
hour= hours;
}

void output (int hour, int minute, char type)
{
cout<< "The time is \t"<< hour << ":"<< minute<< ":"<< second<< " "<< type<< "M"<< endl;
}
May 8, 2016 at 2:50pm
input2(hours, minute, second);
There's no such function.
May 8, 2016 at 2:53pm
What do you mean? what's wrong?
May 8, 2016 at 2:55pm
You can only call a function if that function exists.

There is no function named input2 that takes three int values as parameters.
May 8, 2016 at 4:55pm
ok thank you i fixed it but i have a small problem now i want to write the a zero before minutes and seconds if there are less than 10 i tried setfill ('0') but it didnt work
May 8, 2016 at 5:13pm
After you set the fill, did you set the width (setw) ?
Topic archived. No new replies allowed.