can pls check on my code??

i want to declare variable char on 'p' or 'a'. So i wrote like

char zone = 'a' || 'p';

is that correct?
char type can only hold one character, though that code you posted is valid since that will assign a value of 1 to zone. it's like char zone = 1;
if want to give two option on char zone, how can i acheive it?
i still don't get want you want, but i'm guessing you mean bitwise operation like | and &, and not to be confuse with || and &&
i try to give example like
when a prompt for user to enter char type,
it only accept 'a' or 'p' only. so in this case, how can i do it?
is this what you're trying to do?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;

int main() {
    char zone;
    cout << "enter p or a: ";
    cin >> zone;

    switch(zone) {
        case 'a':
            cout << "You entered a.\n";
            //do something here..
            break;

        case 'p':
            cout << "you entered p.\n";
            //do something here..
            break;

        default:
            cout << "Please enter p or a only!\n";
    }
}
i will try using the exam u gave, because i still encounter problem when i input ':' or '.'
the below is the code .

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
#include <stdafx.h>
#include <stdio.h>

int main(void)
{
	int hour = 0;
	int min = 0;
	int am = 00;
	int pm = 24;
	int format = 0;
        char dot = ':' || '.';
	char zone = 'a' || 'p' ;

	
		printf("Enter time (H:Mx): ");
		scanf_s("%d", &hour);
                scanf_s("%c", &dot);
		scanf_s("%d", &min);
                scanf_s("%c", &zone);
		printf("time is %d",hour);
                printf("%c", &dot);
		printf("%d",min);
		printf("%c\n",zone);


		if ( zone == 'a')
		{
			format = am + hour;
			printf("%d", format);
		}

		else
		{
			format = pm - hour;
			printf("%d", format);
		}
}
Topic archived. No new replies allowed.