Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. a FUNCTION 2 CALCULATE SECONDS since time struck 12

a FUNCTION 2 CALCULATE SECONDS since time struck 12

Scheduled Pinned Locked Moved C#
helptutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    compu2rbloo
    wrote on last edited by
    #1

    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.

    R S C G 4 Replies Last reply
    0
    • C compu2rbloo

      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.

      R Offline
      R Offline
      Rein Hillmann
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • C compu2rbloo

        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.

        S Offline
        S Offline
        Stefan Troschuetz
        wrote on last edited by
        #3

        Simply use the modulus operator to correct the hours value: (hour % 12) The rest was already given by the previous post.


        www.troschuetz.de

        1 Reply Last reply
        0
        • C compu2rbloo

          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.

          C Offline
          C Offline
          compu2rbloo
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • C compu2rbloo

            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.

            G Offline
            G Offline
            Gavin Jeffrey
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups