Search code examples
pseudocode

How could I turn a variable into a number of seconds equal to that variable's number of minutes


I want to turn a variable (let's say with a current value of 20) into a value that is <variable> minutes (in to), so a variable of 20 turns into 1200 (the number of seconds in 20 minutes)

How would I do this (in pseudocode).

I feel like there's a stupid simple answer to this but I just can not think of/find it.


Solution

  • It sounds like you just want to multiply the current value of the variable by 60.

    If the name of the variable is elapsedTime, then this will work in most programming languages, at least imperative ones:

    elapsedTime = elapsedTime * 60 
    

    Some languages in the C tradition let you abbreivate that to just this:

    elapsedTime *= 60
    

    In other languages you might have to use := instead of = for the assignment operation. And in functional languages without mutable variables, you would have to declare a new variable instead of modifying the existing one (which is probably a better approach in general, so you don't get confused by having the same variable representing two different units at different points in the code). But the idea is the same.

    Am I missing some complicating factor?