Help me

Joined
Aug 12, 2022
Messages
6
Reaction score
0
The semester started on Monday of week 1; call that day number 1. On day 8, it was Monday of week 2 and on day 15, it was Monday of week 3.

Write a program which asks the user to enter the number of day and display the result.

a) what day of the week it is
b) what week number it is

Hint: The day of the week is related to the remainder when n−1 is divided by 7, while the week number is related to (n − 1)/7. Modify your program to give the week number and day of the week for any n. (For the day of the week print a number in the range 0-6, which decodes as Mon=0, Tue=1, Wed=2... Sun=6.)
 
Joined
Aug 12, 2022
Messages
6
Reaction score
0
Hi, what have you tried so far?
1660532797057.png

This is what i've tried so far. Can this be accomplished without an if-else statement? I just began learning c programming 2 weeks ago so this is quite challenging for me
 
Joined
Aug 11, 2022
Messages
12
Reaction score
0
The answer is in the hint.

Your input should only be one number, let's say "n = 27"

The lesson is intended to teach you two things: integer division and modulus

Take the input: n = 27

week: ( (n -1) / 7 ) + 1 = 4 (integer division) The +1 is because the weeks are numbered starting at 1 whereas the days are 0-6
day: ( n -1) % 7 = 5 (Saturday) modulus i.e. the remainder

Hope that helps.
 
Joined
Sep 2, 2022
Messages
2
Reaction score
0
correct me if im wrong but you should be using string not char

disregard: c not cpp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top