skip over function arguments?

Hey so I've written a code with functions to prompt for time in 24 hour format, convert time from 24 hour format to 12 hour format and display both. What I am having trouble with is how to display the am/pm for 12 hour format. in my convertTime24to12 function I use math to find if it am/pm and equal the char t a or p, with the m being added later. what I need is in my printtime12 function is to call that function and use the char variable but I cant figure out how without using the other arguments.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
void main()
{
int hour=0;
char ch;
int minutes=0;

getTime24(hour, ch, minutes);
printTime24(hour,ch,minutes);

}

void getTime24(int& hour, char& ch, int& minutes)
{
cout << "Enter a time in 24 hour format (for example 13:45): ";
cin >> hour >> ch >> minutes; 

	while (hour < 0 || hour >= 24 || minutes < 0 || minutes > 60) 
	{
		cout << "I'm sorry the information you entered is not valid. Please try aagin " << endl;
		cin >> hour >> ch >> minutes; 
	}
}


void convertTime24to12(int& hour12, char& a)
{
	if (hour12 > 12)
	{
		hour12 = hour12 - 12;
		a = 'p';
	}
	else
	{
		a= 'a';
	}
}


void printTime24(int hour,char ch,int minutes)
{
	cout << "That time in 24 hour format is: " << hour << ch << minutes;
}

void printTime12(int hour,char ch,int minutes)
{
	cout << "That time in 12 hour format is: " << hour << ch << minutes;
}
Last edited on
Topic archived. No new replies allowed.