Question: In this tutorial you will practice making functions, using a random number generator and using modular arithmetic (%). We will keep an unsigned integer around

 In this tutorial you will practice making functions, using a randomnumber generator and using modular arithmetic (%). We will keep an unsigned

In this tutorial you will practice making functions, using a random number generator and using modular arithmetic (%). We will keep an unsigned integer around for the clock time in seconds and you will initially print out the clock time in hours, minutes and seconds. Then you can take in an amount of time passed from the user (in seconds or feel free to get fancy and give the user options hours, minutes, and seconds followed by the amount). You should then increase the clock by that amount of time and print out the clock time in h:m:s) once again. 1. Get a random time: In main, create an integer to store the number of seconds that have passed in the day (I'll refer to this as clockSec). Notice that you will want to avoid overflow so what if the number of seconds was > the 86400 seconds in a day? Can we use % to ensure the value isn't too large? The TA or I will also go over the rand function but the simplified form: Include "time.h" and "stdlib.h" Call srand(time(NULL)); before getting a random number. This uses the clock time on the computer (so pretty random) to set the random number generator. A call to rand() returns a random number between 0 and RAND_MAX. How can you make sure the range is between 0 and 86400? Set clockSec to this random value. 2. printTime function: Make a function that takes an unsigned int (like clockSec) and prints to the console the time in hours: minutes : seconds. Notice that this purely requires arithmetic to get those 3 values. Assume a 12 hour clock. Make sure you test your function. 3. user input and add Time Prompt the user to type in an amount of time that has passed (including negative values). Make a new function addTime that takes an unsigned int (the time in seconds) and a duration (seconds to increase the clock by) and returns the revised clock time to be stored back in to clockSec). If you went fancy and got hour, minute and second time changes from the user then your addTime function will have parameters hoursToAdd, minutes2Add, and secondsToAdd. Feel free to wear a monocle when writing this; that code is pretty fancy. Make sure you test your code. 4. printTime 24 function: Finally, make a function printTime24 that takes clockSec and prints out clock information if it was a 24 hour clock

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!