Convert 24 hour format to 12 hour AM/PM

Apr 21, 2020 at 7:19pm
Hello everyone, hope you are all safe and sound.
I am running a simple program using 3 functions to convert from 24 hours to 12 hours. But I seem to be getting a lot of error which I do not really understand.
Errors such as "Illegal use of void" or "Undeclared identifier" etc...

I have the code here, I hope you can clarify the errors.
Thank you all

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
49
#include <iostream>
#include <cmath>

using namespace std;

void input(int& hours24, int& minutes);
void convert(int& hours, char& AMPM);
void output(int hours, int minutes, char AMPM);

int main() {
	cout << "-----------------------------Convert from 24-hour format to 12 hour format--------------------\n";
	int hour, min,
		char choice, AMPM;
	do {
		void input(hour, min);
		void convert(hour, min, AMPM);
		void output(hour, min, AMPM);
		cout << "/n";
		cout << "To complete press y or Y: "; cin >> choice;


	} while (choice == 'Y' || choice == 'y');
}


void input(int& hours24, int& minutes) {
	cout << "Enter your time in hours and minutes"; cin >> hours24; cin >> minutes;

}

void convert(int& hours, char& type) {
	if (hours > 12) {
		hours -= 12;
		type = 'P';
	}
	else {
		type = 'A';
	}
}



void output(int hours, int minutes, char type) {

	cout << "In 12 hour notation: " << hours << ":" << minutes << " " << type << "";

}

  
Apr 21, 2020 at 7:28pm
Look at the FIRST error. It has a line number on it.

Look at that line, and look at the line before it:

1
2
int hour, min,
		char choice, AMPM;


See anything wrong here? What's that, after min ? What should be there?
Apr 21, 2020 at 7:30pm
1
2
do {
		void input(hour, min);


That second line. That is NOT how to call a function. That is how to declare a function. I expect you meant this:

1
2
do {
		input(hour, min);



I appreciate your enthusiasm, but you would benefit from going back and writing a program in which you create one function, and call it. So that you can practice the basics of creating a function, and calling it.
Apr 21, 2020 at 7:31pm
Excuse my vision, I have fixed that. But I don't seem to understand what "Incomplete type means" I am using visual studio, and it gives that error.
Apr 21, 2020 at 7:36pm
It means that it doesn't recognise some class or type you're trying to use.

You've told it to create an int named "char choice". That makes no sense. Don't do that.
Apr 21, 2020 at 8:00pm
Alright, the code works as I want and it works nicely.

Thank you for the answers!
Topic archived. No new replies allowed.