reset password
Author Message
Dark
Posts: 2
Posted 19:53 Feb 11, 2017 |

I seem to be having trouble with with problems 04 and 05. With 0 I cant seem to write  proper formula that works for calculation future days. In 05 on the other hand I am unsure of show to display the days, hours and minutes together if a value that meets all 3 conditions. Does any one have any hints or tips I can use to try to fix my code.

Roland0g
Posts: 2
Posted 20:22 Feb 11, 2017 |

For number 5 try dividing the distance by the miles then multiple it by the price

Edited by Keenan: Response to homework from Dr. Guo's CS2011 class.

Last edited by kknaur at 11:54 Feb 12, 2017.
tkitcha
Posts: 19
Posted 20:38 Feb 11, 2017 |

My understanding in problem 5 is that if the user enters less than 60 seconds, then display how many seconds

If more 60 seconds, display how many minutes. In other word, you need to show only one result according to the input.

Please correct if I'm wrong. <.<

 

For problem 4

Hint: Combine both inputs and divide it by 1 week.

 

Hope this help a bit.

Last edited by tkitcha at 20:40 Feb 11, 2017.
sdo8
Posts: 54
Posted 22:13 Feb 11, 2017 |

Problem 4 can be quite tricky. The question gives the hint as to what values should be printed for which inputted day it is. ex(Sunday 0, Monday 1, Tuesday 2, etc.). The question also hints at using the % operator (This is a HUGE hint) for the future day. Remember that the future day is just the DAY(mon, tuesday, weds, etc.) and not the actual date(Jan. 30, Feb. 20, etc.). 

Problem 5 only asks for 1 measurement of time depending on how many seconds are inputted. This means that 90 seconds should be just be equal to 1.5 minutes, and 3600 seconds should equal 1 hour. Read the questions carefully, the way that they are worded will help you figure out pretty much exactly what you need to do.

If you're thinking that your code is too long, that's okay. Sometimes the best solutions are simple solutions.

kknaur
Posts: 540
Posted 11:52 Feb 12, 2017 |

@Rolandog: Hmm this seems to be a response to a question from a separate section of CS2011. I have three sections of CS2011 and Dr. Guo has one section.  My assignments are different from her assignments.  Thanks for trying to help anyways!

For problem 4 a hint would be to use the mod (%) operator for future days.  When you mod a number by a value n the result will always be a value between 0 and n - 1 inclusive. I.E. if you mod something by 4 your answer would always be something between 0 and 3 inclusive.

For problem 5 here is an example, if I put in 100000 seconds the output might be something like:

There is/are about 1 day(s) in 100000 seconds.
There is/are about 27 hour(s) in in 100000 seconds.
There is/are about 1666 minute(s) in 100000 seconds.

It is ok to use integer math for this problem.

jgarc629
Posts: 76
Posted 14:02 Feb 12, 2017 |

Does anyone know if a variable can be modded? Is it only numbers? I'm not sure how to express the mod part and I don't know if it needs to be its own line or can it be in the same line of the math operations. 

 

(HW03P04)

Last edited by jgarc629 at 14:03 Feb 12, 2017.
kknaur
Posts: 540
Posted 14:08 Feb 12, 2017 |
jgarc629 wrote:

Does anyone know if a variable can be modded? Is it only numbers? I'm not sure how to express the mod part and I don't know if it needs to be its own line or can it be in the same line of the math operations. 

 

(HW03P04)

mod (%) is a mathematical operation that gives you the remainder of division.  You can use the mod operator anywhere it would be valid to use any of the other four basic math operations (+, - , /, *).  Just like these other operators, mod can be applied to numeric literals or numeric variables.

jgarc629
Posts: 76
Posted 14:38 Feb 12, 2017 |

I've checked the notes but I'm still confused. If I were to want to find the remainder of something (x) divided by 20, would I write x%20? That would print the remainder off that right?  

kknaur
Posts: 540
Posted 14:42 Feb 12, 2017 |
jgarc629 wrote:

I've checked the notes but I'm still confused. If I were to want to find the remainder of something (x) divided by 20, would I write x%20? That would print the remainder off that right?  

This would give you the remainder of dividing x by 20.

jgarc629
Posts: 76
Posted 15:17 Feb 12, 2017 |

Okay I get it now, thanks!