0
Help me with this program
Help me please I'm new student in cs I need easiest and simple method i do not want hard method or complex i must write c program to read from user month in number and also day and print the number of week the day belongs note:year=52weeks
10 Answers
+ 5
Assuming you want this year only, you should lookup the physical first day of the first week.
Make an array or month variables to store the actual number of days that count towards the weeks for each month. Some of January and December may not be consider in the 52 weeks of this year. January may have some of last year's December in it's first week.
Sum up the months that are completed prior to your input month. Add in the day of the month you got minus one. If January, increase by December's days. Divide by seven and add one to get your week number.
+ 4
XÄcen ÄÄi updated your code with Janningâ's running total idea to finished product.
https://code.sololearn.com/cHvCjYOdS4ln
+ 2
XÄcen ÄÄi , Welcome to SoloLearn!
This community is here to support your learning. If we did your work for you, especially before you've shown any attempts, we would be taking away your opportunity to learn and grow. đ
John has walked you through the logic -- try to put that in a project so we can continue to help you from there.
It may also be helpful to review the following post on how to get the most out of this forum:
https://www.sololearn.com/Blog/38/8-simple-rules-to-get-help-from-the-community/
Be sure not to miss the link to the Community Guidelines toward the bottom of the article.
Looking forward.
+ 2
OMGGGGG THXXXXXXXXXXXXXXXXX YOU TRILLION TIMES DEAR
+ 2
Oh, I see. The offset is also built in. Very nice. đ Thanks, John Wells !
+ 2
According to week number link in my program comment, Dec 31 is first day in week 1 of next year so week 53 in this year.
+ 1
We'd be happy to help fix anything you have tried that isn't working.
Please provide a link to your Code Playground code so we can help you troubleshoot the specific issues you are running into.
The Code Playground should be relatively easy to find in the website version of SoloLearn, but if you are in the app version, it can be accessed via the curly braces, green circle with plus sign to add a new project, then select the project type.
Looking forward.
+ 1
I'm trying
+ 1
#include <stdio.h>
int main()
{
int day , month, week, sum, sum2,sum3;
printf("Enter day\n");
scanf("%d", &day);
printf("Enter Month\n");
scanf("%d" , &month);
sum = month*4.333333336;
sum2 = sum*7;
sum3 = sum2+day;
week = sum3/7;
printf("week number = %d \n", week);
return(0);
}
+ 1
I think, based on John's clue, (maybe he can correct me if I'm leading you astray,) the pseudocode for the array would be something like:
[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
(Not sure if you'd actually need the number of days in December though...)
and loop over the array, or, more simply, precalculate the running total into the array so you don't have to loop over it. Maybe:
[31, 59, 90, 120, etc.]
Then do the rest of the math, keeping in mind that arrays start at zero instead of one.