This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
notes:cprog:spring2024:projects:mmf0 [2023/09/07 20:23] – created wedge | notes:cprog:spring2024:projects:mmf0 [2024/02/29 01:53] (current) – [Add quartered value back to two digit year] hcopp1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ======MMF0====== | ||
+ | =====Process===== | ||
+ | |||
+ | ====Input value as short int (all four digits)==== | ||
+ | |||
+ | ====Obtain the last two digits of this input value==== | ||
+ | |||
+ | -In order to obtain the last two digits of this input value, you can create a new variable and set that to be the result of the input year variable, divided by the integer division remainder (%) followed by 100. This is because a four-digit number, divided by 100 will yield a remainder in the tenth' | ||
+ | |||
+ | -For example: short unsigned int new = year % 100 | ||
+ | ====Quarter the value==== | ||
+ | subtract 2000 from the given year, and then divide by 4 using the "/" | ||
+ | |||
+ | NOTE: Use () to ensure the code does things in the order you want. | ||
+ | ====Add quartered value back to two digit year==== | ||
+ | Add quartered value (output of last sections equation) to the last two digits of the current year (output of first section). | ||
+ | ====Subtract best fitting multiple of seven==== | ||
+ | |||
+ | ====Look up day in table==== | ||
+ | |||
+ | ^ Day ^ Value | | ||
+ | | Monday | ||
+ | ^ Day ^ Value | | ||
+ | | Tuesday | ||
+ | ^ Day ^ Value | | ||
+ | | Wednesday | ||
+ | ^ Day ^ Value | | ||
+ | | Thursday | ||
+ | ^ Day ^ Value | | ||
+ | | Friday | ||
+ | ^ Day ^ Value | | ||
+ | | Saturday | ||
+ | ^ Day ^ Value | | ||
+ | | Sunday | ||
+ | ^ Day ^ Value | | ||
+ | | Sunday | ||
+ | ====Edge case: leap years==== | ||
+ | |||
+ | To find the edge case you have to check if there is a remainder when dividing the year by 4 | ||
+ | =====SELECTION===== | ||
+ | |||
+ | ====if statements==== | ||
+ | if statements are written as "if (condition){ the thing you want to happen } | ||
+ | |||
+ | If the condition is not met, "the thing you want to happen" | ||
+ | ====else if==== | ||
+ | |||
+ | <color # | ||
+ | |||
+ | Example: | ||
+ | < | ||
+ | if (condition0) | ||
+ | { | ||
+ | If condition0 is met do this .... | ||
+ | } | ||
+ | else if (condition1) | ||
+ | { | ||
+ | if condition0 isn't met and condition1 is; Do this .... | ||
+ | } | ||
+ | </ | ||
+ | ====else==== | ||
+ | |||
+ | |||
+ | ELSE is put at the end of a IF statement. ELSE will first check if the condition of the original IF statement was met, if it wasn't met, It then does something | ||
+ | |||
+ | Example: | ||
+ | < | ||
+ | if (condition0) | ||
+ | { | ||
+ | If condition0 is met do this .... | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | if condition0 isn't met do this .... | ||
+ | } | ||
+ | </ | ||
+ | ====RELATIONAL OPERATORS==== | ||
+ | |||
+ | ^ Operator | ||
+ | | == | is equal to | | ||
+ | | != | is not equal to | | ||
+ | | < | ||
+ | | > | ||
+ | | < = | less than or equal to | | ||
+ | | > = | greater than or equal to | | ||
+ | =====VERIFY RESULTS===== | ||
+ | To verify your results, ./ | ||
+ | |||
+ | Remember to only use **stdout** to print the days of the week [EX: fprintf(stdout, |