fork download
  1. //as a case statement
  2. #include <stdio.h>
  3. // John Gautreaux
  4. // john.gautreaux@g.austincc.edu
  5. // Graded Assignment 50%
  6. // http://w...content-available-to-author-only...t.com/moodle/mod/assignment/view.php?id=3546
  7.  
  8. int main () {
  9. // Variables
  10.  
  11. char name[150];
  12. int age;
  13. int age_check;
  14.  
  15. //Main Code
  16. printf("Can I see some ID?\n");
  17. printf("What’s your name and age please?\n");
  18. scanf("%s %d", name, &age );
  19.  
  20. switch(age_check){
  21. case 'under-20' :
  22. (age <= 20) // ********* check their ID to see if they are 20 or younger
  23. printf("Hey %s\t\n", name);
  24. printf("%d years old is too young get into a bar.\n", age);
  25. break;
  26.  
  27. case '20-60' :
  28. (age>20 && age<=60) // ********* See if they are older than 20, but are 60 or younger
  29. printf("Sorry about that %s\n", name);
  30. printf("You don't look %d years old.\t\n", age);
  31. printf("You're an adult now it seems.\n");
  32. break;
  33.  
  34. case '61 and over' :
  35. age > 60) // ********* See if they are older than 60
  36. printf("%s, Can i help you cross the street?\n", name);
  37. printf("Looks like you are getting up there in age.\n");
  38. printf("I can't believe you are\t%d years old.\n",age);
  39. break;
  40.  
  41. default : //********** No ID
  42. printf("Did you lose your ID?\n");
  43. printf("I can't let you in if you can't tell me your name and age\n");
  44. }
  45. return 0;
  46. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘main’:
prog.c:21:7: warning: character constant too long for its type
  case 'under-20' :
       ^~~~~~~~~~
prog.c:22:8: warning: statement with no effect [-Wunused-value]
   (age <= 20)  // ********* check their ID to see if they are 20 or younger
   ~~~~~^~~~~~
prog.c:23:4: error: expected ‘;’ before ‘printf’
    printf("Hey %s\t\n", name);
    ^~~~~~
prog.c:27:8: warning: character constant too long for its type
  case  '20-60' :
        ^~~~~~~
prog.c:28:11: warning: statement with no effect [-Wunused-value]
   (age>20 && age<=60)  // ********* See if they are older than 20, but are 60 or younger
   ~~~~~~~~^~~~~~~~~~~
prog.c:29:4: error: expected ‘;’ before ‘printf’
    printf("Sorry about that %s\n", name);
    ^~~~~~
prog.c:34:7: warning: character constant too long for its type
  case '61 and over' :
       ^~~~~~~~~~~~~
prog.c:35:7: warning: statement with no effect [-Wunused-value]
   age > 60) // ********* See if they are older than 60
   ~~~~^~~~
prog.c:35:11: error: expected ‘;’ before ‘)’ token
   age > 60) // ********* See if they are older than 60
           ^
prog.c:35:11: error: expected statement before ‘)’ token
stdout
Standard output is empty