F
flebber
I have recreated the program date.c from the book. However I am
getting alot of errors when compiling the code. This is the code
directly as I have typed it in.
#include <stdio.h>
int main(void)
{
int month, day, year;
printf("Enter the date mm/dd/yyyy: ");
scanf("%d / %d /%d" &month &day &year);
printf("Dated this %d", day);
switch (day) {
case1: case21: case31:
printf("st"); break;
case2: case22:
printf("nd"); break;
case3: case23:
printf("rd"); break;
default: printf("th"); break;
}
printf(" day of ");
switch (month){
case1: printf("January"); break;
case2: printf("February"); break;
case3: printf("March"); break;
case4: printf("April"); break;
case5: printf("May"); break;
case6: printf("June"); break;
case7: printf("July"); break;
case8: printf("August"); break;
case9: printf("September"); break;
case10: printf("October"); break;
case11: printf("November"); break;
case12: printf("December"); break;
}
printf(", 20%.2d.\n", year);
return 0;
}
The errors start stating that we have duplicate cases, case1(day) is
duplicate to case1 (month).
Am I doing something wrong?
These are the exact errors.
|| /home/sayth/My_Programs/C/dae.c: In function ‘main’:
/home/sayth/My_Programs/C/dae.c|8 col 22 error| invalid operands to
binary & (have ‘char *’ and ‘int’)
/home/sayth/My_Programs/C/dae.c|23 col 3 error| duplicate label
‘case1’
/home/sayth/My_Programs/C/dae.c|12 col 3| note: previous definition of
‘case1’ was here
/home/sayth/My_Programs/C/dae.c|24 col 3 error| duplicate label
‘case2’
/home/sayth/My_Programs/C/dae.c|14 col 3| note: previous definition of
‘case2’ was here
/home/sayth/My_Programs/C/dae.c|25 col 3 error| duplicate label
‘case3’
/home/sayth/My_Programs/C/dae.c|16 col 3| note: previous definition of
‘case3’ was here
/home/sayth/My_Programs/C/dae.c|34 col 3 warning| label ‘case12’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|33 col 4 warning| label ‘case11’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|32 col 3 warning| label ‘case10’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|31 col 3 warning| label ‘case9’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|30 col 3 warning| label ‘case8’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|29 col 3 warning| label ‘case7’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|28 col 3 warning| label ‘case6’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|27 col 3 warning| label ‘case5’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|26 col 10 warning| label ‘case4’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|16 col 10 warning| label ‘case23’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|16 col 3 warning| label ‘case3’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|14 col 10 warning| label ‘case22’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|14 col 3 warning| label ‘case2’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|12 col 18 warning| label ‘case31’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|12 col 10 warning| label ‘case21’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|12 col 3 warning| label ‘case1’
defined but not used [-Wunused-label]
getting alot of errors when compiling the code. This is the code
directly as I have typed it in.
#include <stdio.h>
int main(void)
{
int month, day, year;
printf("Enter the date mm/dd/yyyy: ");
scanf("%d / %d /%d" &month &day &year);
printf("Dated this %d", day);
switch (day) {
case1: case21: case31:
printf("st"); break;
case2: case22:
printf("nd"); break;
case3: case23:
printf("rd"); break;
default: printf("th"); break;
}
printf(" day of ");
switch (month){
case1: printf("January"); break;
case2: printf("February"); break;
case3: printf("March"); break;
case4: printf("April"); break;
case5: printf("May"); break;
case6: printf("June"); break;
case7: printf("July"); break;
case8: printf("August"); break;
case9: printf("September"); break;
case10: printf("October"); break;
case11: printf("November"); break;
case12: printf("December"); break;
}
printf(", 20%.2d.\n", year);
return 0;
}
The errors start stating that we have duplicate cases, case1(day) is
duplicate to case1 (month).
Am I doing something wrong?
These are the exact errors.
|| /home/sayth/My_Programs/C/dae.c: In function ‘main’:
/home/sayth/My_Programs/C/dae.c|8 col 22 error| invalid operands to
binary & (have ‘char *’ and ‘int’)
/home/sayth/My_Programs/C/dae.c|23 col 3 error| duplicate label
‘case1’
/home/sayth/My_Programs/C/dae.c|12 col 3| note: previous definition of
‘case1’ was here
/home/sayth/My_Programs/C/dae.c|24 col 3 error| duplicate label
‘case2’
/home/sayth/My_Programs/C/dae.c|14 col 3| note: previous definition of
‘case2’ was here
/home/sayth/My_Programs/C/dae.c|25 col 3 error| duplicate label
‘case3’
/home/sayth/My_Programs/C/dae.c|16 col 3| note: previous definition of
‘case3’ was here
/home/sayth/My_Programs/C/dae.c|34 col 3 warning| label ‘case12’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|33 col 4 warning| label ‘case11’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|32 col 3 warning| label ‘case10’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|31 col 3 warning| label ‘case9’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|30 col 3 warning| label ‘case8’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|29 col 3 warning| label ‘case7’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|28 col 3 warning| label ‘case6’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|27 col 3 warning| label ‘case5’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|26 col 10 warning| label ‘case4’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|16 col 10 warning| label ‘case23’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|16 col 3 warning| label ‘case3’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|14 col 10 warning| label ‘case22’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|14 col 3 warning| label ‘case2’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|12 col 18 warning| label ‘case31’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|12 col 10 warning| label ‘case21’
defined but not used [-Wunused-label]
/home/sayth/My_Programs/C/dae.c|12 col 3 warning| label ‘case1’
defined but not used [-Wunused-label]