Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

mugwump101

  • 3 years ago

Write a function named `dayCount()` that accepts a month, day, and year as its input arguments; calcuates an integer representing the total number of days from the turn of the century to the date that's passed; and returns the calculated integer to the calling function. For this problem, assume each year has 365 days and each month has 30 days. You need to write a main function to prompt for year, month and day. You need to validate the input and ask user reenter one if not correct. Note you should use exact function name in your program.

  • This Question is Closed
  1. Narsat
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    int dayCount(int day, int month, int year) { total=day + (month *30) + ((year-2000) *365); return total; } For the turn of the century, you need the closest 100, you should use year%100, which will yield the last two digits of the year. If year 1999, it will yield 99. If 2011, it will yield 11.

  2. Narsat
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    I just saw your code limits the year to be bigger than 2000, but anyway using the year%100 should yield correct answer to any number larger than 2100. Since the restrictions of the problem do not include the year, I would probably remove the year limitation, probably set it to any non-negative number?

  3. mugwump101
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    hmmm perhaps you are right. I was confused about the turn of the century dillemma. Let me know it out. Thanks a bunch :D

  4. Narsat
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    Good luck :)

  5. mugwump101
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Doesn't work out :( lol. It says, the tests fail on -Test Failed on invalid inputs -Test Failed on y=3985, m=1, d=15 -Test Failed on y=2011, m=10, d=5

  6. mugwump101
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Example 1: Enter a correct year (>=0): -5 Enter a correct year (>=0): 2001 Enter a correct month (>=1 and <=12): 15 Enter a correct month (>=1 and <=12): 1 Enter a correct day: -12 Enter a correct day: 36 Enter a correct day: 15 The total days are: 380 Example 2: Enter a correct year (>=0): 3045 Enter a correct month (>=1 and <=12): 1 Enter a correct day: 15 The total days are: 16440 Here are example problems my professor posted :/

  7. Narsat
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    What are the outputs for your failed tests?

  8. mugwump101
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    For d=15, m=1 and year =3985, my output is 31070 :/

  9. Narsat
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    Ah, I think I see the mistake. You're multiplying month: 1 as 30 days. At month 1 technically you still haven't gone through 30 days. Try modifying ((month-1) * 30) inside the dayCount() function

  10. mugwump101
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Hmmm really? 1 month =30 days though right? or are you saying at month 1, 30 days haven't passed yet?

  11. Narsat
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    At month 1, you still haven't gone through 30 days. As in m = 1 d = 15 You're at January 15, therefore you're at day 15, not 45 as your function would now return.

  12. mugwump101
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    and yeah, it still fails

  13. mugwump101
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    oh hmmm

  14. Narsat
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    This operation returns the correct value: day + (month-1) * 30 + (year%100) * 365; What is checking if your tests succeed or fail, an automatic program where you submit your code?

  15. mugwump101
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    yeah an automatic program

  16. mugwump101
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yeah I thought it would work but it doesn't work on the program for some reason :( I wonder what i am doing wrong...

  17. Narsat
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    Normally, automatic programs check output down to the last space and comma, that is, your program should output EXACTLY as shown in the example. do { cout <<"Enter a correct year: "; cin >> year; } while(year<0); should be do { cout <<"Enter a correct year (>= 0): "; cin >> year; } while(year<0); and so on.

  18. mugwump101
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    It shouldn't and it doesn't change anything because you can write anything in the cout string but idk... Thanks for the help anyway :D I appreciate it :D

  19. Narsat
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    The times I've struggled with automatic checkers have been with a randomly inserted space I missed, double check just to make sure. What do you mean you can write anything in the cout String, whoever is running the application can't actually modify cout at runtime can they? (Don't know much about C#)

  20. mugwump101
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Oh no they can't. I meant to say cout <<"Enter a num: " << num << endl; and cout << "Num: " << num << endl; give you the same output regardless (taking your last post as an example)...Idk what could be wrong though and yeah checkers are annoying a bit in that regard.

  21. mugwump101
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Can you take a look at my other question too if you have the time? I just want feedback. Thanks a bunch!!! :D

  22. agdgdgdgwngo
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    i did something like this in C a while ago...

  23. agdgdgdgwngo
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    heres the function http://ideone.com/sw3ux

  24. agdgdgdgwngo
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    mine does something diffferent tho :-P

  25. Not the answer you are looking for?
    Search for more explanations.

    Search OpenStudy
    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.