a FUNCTION 2 CALCULATE SECONDS since time struck 12
-
Hi...newbie here...yes it smells like an assignment but please if anyone can help with a formula on how to get this one. My head is spinning....i've only got the inputs and im suppose to create a function not use the ones in the standard library.......pleasssse help with anything...................something...... ^^^^^^^^^^^^^^^^ Write a function that takes the time as three integer arguments (hours, minutes and seconds) and returns the number of seconds since the last time the clock “struck 12.” Use this function in a program to calculate the amount of time in seconds between two times, both of which are within one 12-hour cycle of the clock.
-
Hi...newbie here...yes it smells like an assignment but please if anyone can help with a formula on how to get this one. My head is spinning....i've only got the inputs and im suppose to create a function not use the ones in the standard library.......pleasssse help with anything...................something...... ^^^^^^^^^^^^^^^^ Write a function that takes the time as three integer arguments (hours, minutes and seconds) and returns the number of seconds since the last time the clock “struck 12.” Use this function in a program to calculate the amount of time in seconds between two times, both of which are within one 12-hour cycle of the clock.
Assuming you're only using 12 hour clocks and not 24 hour: return (hour*60*60) + (minute*60) + second; If my assumption is incorrect then you simply need to subtract 12 from hour if hour >= 12. As for the second part - call the function twice and then take the absolute value of the difference of the two times.
-
Hi...newbie here...yes it smells like an assignment but please if anyone can help with a formula on how to get this one. My head is spinning....i've only got the inputs and im suppose to create a function not use the ones in the standard library.......pleasssse help with anything...................something...... ^^^^^^^^^^^^^^^^ Write a function that takes the time as three integer arguments (hours, minutes and seconds) and returns the number of seconds since the last time the clock “struck 12.” Use this function in a program to calculate the amount of time in seconds between two times, both of which are within one 12-hour cycle of the clock.
Simply use the modulus operator to correct the hours value: (hour % 12) The rest was already given by the previous post.
-
Hi...newbie here...yes it smells like an assignment but please if anyone can help with a formula on how to get this one. My head is spinning....i've only got the inputs and im suppose to create a function not use the ones in the standard library.......pleasssse help with anything...................something...... ^^^^^^^^^^^^^^^^ Write a function that takes the time as three integer arguments (hours, minutes and seconds) and returns the number of seconds since the last time the clock “struck 12.” Use this function in a program to calculate the amount of time in seconds between two times, both of which are within one 12-hour cycle of the clock.
this is what i got...can anyone help integrating the formula suggested into this.........? to make it simpler.....? #include using std::cout; using std::cin; using std::endl; int main () { int time(int,int,int); int h,h2; // 0-23 int m,m2; // 0-59 int s,s2; // 0 -59 cout <<"Please enter 2 times: "<> h; cout <<"enter minute for the 1st time: "<> m; cout <<"enter seconds for the 1st time : "<> s; cout <<"Please enter the 2nd time: "<> h2; cout <<"enter minute for the 2nd time: "<> m2; cout <<"enter seconds for the 2nd time : "<> s2; cout <<"According to the times entered,"<< endl; cout<<"the difference between the two times in seconds is "<12) min = hh * 60; sec = min * 60; //converts hours to seconds if (mm>0) sec2 = mm * 60; //converts minutes to seconds int x = sec + sec2+ss; //total seconds return x; //returns total seconds
-
Hi...newbie here...yes it smells like an assignment but please if anyone can help with a formula on how to get this one. My head is spinning....i've only got the inputs and im suppose to create a function not use the ones in the standard library.......pleasssse help with anything...................something...... ^^^^^^^^^^^^^^^^ Write a function that takes the time as three integer arguments (hours, minutes and seconds) and returns the number of seconds since the last time the clock “struck 12.” Use this function in a program to calculate the amount of time in seconds between two times, both of which are within one 12-hour cycle of the clock.
Hi newbie, Well this sounds like a mathematical function that you would have to make something like - public int returnSecondsSinceTwelve(int hour, int minute, int second) { int timeSinceTwelve = 0; if(hour > 12) { timeSinceTwelve = hour - 12; } else if(hour < 12) { timeSinceTwelve = hour; } timeSinceTwelve = timeSinceTwelve * 60 * 60; minute = minute * 60; return timeSinceTwelve + minute + second; } i havent tried this function so i dont gaurantee that it will work (i just wrote it roughly and really quick) but the basic theory is - to get seconds out of an hour multiply it by 60 (minutes) and then again by 60 (seconds) - to get seconds out of an minute multiply it by 60. Then add these all up (including second which is already in the right format) and you will get the total seconds. Hope this clears thins up.