getting error

i am trying to convert 24 hour notation to 12 hour but i am getting an error
can anyone help me ?
(the error is in char type)

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
50
51
52
53
54
55
56
57
58
 #include <iostream>
using namespace std;

void convertTime(int hour , char& type);
void getTime(int& hour,int& minute);
int output(int hour, int minute, char type);

int main()
{
	int hour;
	int minute;
	char type;
	char answer;

	do
	{
		getTime(hour, minute);
		convertTime(hour, type);
		hour = output(hour,minute, type);

		cout <<" perform another calculation" << endl;
		cin >> answer;
	} while (answer == Y);
	return 0;
}


void getTime(int& hour, int& minute)
{
	cout << "Write the time in HR:Min" <<endl;
	cin >> hour>> minute;
}
void convertTime(int hour, char& type)
{
	int time;
	
	if (hour < 12)
	{ 
		type = "A";
	}
	if (hour > 12)
	{	
		time = 12 - hour;
		type = "P" ;
	}
}
int output(int hour, int minute, char type)
{
	cout << "the time converted to 12 hr format is " << hour << minute;
	if (type == 'A')
	{
		cout << "AM"<<endl;
	}
	else
	{
		cout << "PM" << endl;
	}
}
Hi @newprog135,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//ctype.cpp
//##

#include <iostream>
using std::cout;
using std::endl;

#include <string>
using std::string;


int main(){

        char holdACharacter='A'; //<-- Single quotes ' ' for characters
        string holdAString="A";  //<-- double quotes " " for strings

        cout<<holdACharacter<<endl;
        cout<<holdAString<<endl;
}//end of main
---
./ctype 
A
A


can you get it? :P

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void convertTime(int hour, char& type)
{
	int time;
	
	if (hour < 12)
	{ 
		type = "A"; //<--- error: double quotes for char variable
	}
	if (hour > 12)
	{	
		time = 12 - hour;
		type = "P" ; //Same here
	}
}



Last edited on
hi @eyenrique
thanks for replying but i cant get it. :P
cant we just do it by using just parameters and overloading?because thats the chapter i have reached so far .
Check again! :)
thank you @eyenrique :)
You are welcome!
Topic archived. No new replies allowed.