C code help switch section

I cannot figure out why the code is giving me a $ at the end of the output in code academy terminal and a % in my personal tmux terminal when i compile out of neovim.
Screenshot from 2024-06-23 16-04-34

#include <stdio.h>

int main(void) {
int month, day, year;

// Standard date form
printf(“Enter date (mm/dd/yyyy): “);
// Split the user input into 3 variables for the date
// Don’t worry about the scanf() below, you’ll learn more about these later!
scanf(”%d /%d /%d”, &month, &day, &year);

// Print the month
switch (month) {
case 0x1:
printf("January ");
break;
case 0x2:
printf("February ");
break;
case 0x3:
printf("March ");
break;
case 0x4:
printf("April ");
break;
case 0x5:
printf("May ");
break;
case 0x6:
printf("June ");
break;
case 0x7:
printf("July ");
break;
case 0x8:
printf("Augest ");
break;
case 0x9:
printf("September ");
break;
case 10:
printf("October ");
break;
case 11:
printf("November ");
break;
case 12:
printf("December ");
break;
default:
printf("Invalid month ");

}

// Print the day
printf(“%d”, day);

// Print the suffix for a given day

switch (day){
case 1: case 21: case 31:
printf("st ");
break;
case 2: case 22:
printf("nd ");
break;
case 3: case 23:
printf("rd ");
break;
default:
printf("th ");
}

  //Print the year.
  printf("%d" , year);

return 0;
}

We fail to see the reason you are using HEX in your case expressions. Care to explain?

As for the mysterious output, that is due to the omitted newline:

printf("%d\n", year);

ahh ok, Thank you for that.

I switched to using hex because I was getting an error for digits 8 and 9. Invalid digit ‘8’ in octal constant. I did some digging and realized it was because I was using 01, 02 - 09. I learned octal’s only go to 07. I did the numbers that way because that’s how I would input in a month if asked to input in a date as xx/xx/xxxx.

Thinking about it now I don’t think I tried doing just 1,2 - 9 without the zeros to see what would happen. It was just in my head from how I read the instructions that it should be in that format.

You will have to forgive me. This is my first time learning any coding and it took me a while to actually write that.

1 Like

As a given we had the format that the ‘scanf’ was prepared to unpack. Three variables got loaded, and no indication of their being hexadecimal in nature is given. It’s as about as out of place as a chocolate teapot.

We don’t force our expectations on an already prescribed environment, but learn to flesh out what is promised by the same. On further thought we will find no surprises.

That brings us back to the inputs. So far, they are integers and there is no reason to change that. The switch statement is largely bent upon integer case expressions, or anything that resolves to integer.

Consider that, 09 can hardly resolve to integer since it does not exist in that number base (octal); and, 0xG (hex) will raise the same error, we suspect, without testing. The compiler is sure to catch these. The long and short is that number base is a big deal in programming, and we don’t wave it around like HTML tags.