My program does not go to switch case.
Apr 12, 2010 at 4:09am UTC
Im writing an project on time format conversion. Why my program does not use case 'a' and case 'p', when i input 'a' or 'p'? can correct for me? Because i want to check when we input 'a' or 'p' only. Please help
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
#include <Stdafx.h>
#include <stdio.h>
int main()
{
int hour = 0;
int min = 0;
int am;
int pm;
char dot = ':' ;
char zone;
printf("Enter time (H:Mx) : " );
scanf_s("%d" ,&hour);
scanf_s("%c" ,&dot);
scanf_s("%d" ,&min);
scanf_s("%c" ,&zone);
switch (zone)
{
case 'a' :
am = 00 + hour;
printf("%d" ,am);
break ;
case 'p' :
pm = 24 - hour;
printf("%d" ,pm);
break ;
default :
printf("You enter a wrong time format\n" );
}
}
Apr 12, 2010 at 6:01am UTC
I think you will find that switch takes an int not a char. So change zone type to int.
Apr 12, 2010 at 6:10am UTC
nope, in a switch case control statement, the control variable must be of an int or char type only.
Topic archived. No new replies allowed.