I won't be asking for a source code yet. What I need to figure out is the process of a certain Math problem with the equation that seemed to be impossible to be converted to source code.

Here it goes:

A certain waveform is 0 volts for time less than 2 seconds and 3 volts for time equal to or greater than 2 seconds. (These waveforms are referred to as step functions.) Prompt the user accepts time in the variable named time and displays the appropriate voltage, depending on the input value.

So the problem is asking for a program for voltage/seconds relation. The user inputs any duration (in seconds) and it is supposed to display the appropriate voltage.

This problem, I guess, is an example of step/greatest integer function, having the equation y= n<=x or where n is the greatest integer less than or greater than x. Step function also follows the equation y=[[x]].

So if a user inputs 5 seconds, it should display 6 volts. If a user inputs 9 seconds, it should display 12 volts.

So...how do I convert the equation to a proper process for source code?

The way I read it is, for every 2 seconds of time elapsed the output increases by 3 volts. However the voltage won't increase until 2 full seconds have elapsed. If this is correct then: (INT(input_time/2)X2)X1.5=voltage_output

## All 9 Replies

The way I read the problem is that the program should print either 0 or 3 depending on the time. There is no equation for that, just a simple if/else statement.

According to your question, this is what program should do.

``````    1. Input time from user.
2. if input<2 display result 0V
3. else if input>2 display result 3V
4. End
``````

but how about the time beyond 2? as what I understood in the problem, users will input any value aside from the given, which is 0 and 2 seconds...how should I solve for other volts? (hope you get what I mean TT.TT)

As there are only 2 possible ouputs, so the above algorithm when converted to code will automatically take care of every value of natural number. Whether its -999999 or +999999. Answer will be 0V for -999999 & 3V for +999999.

The way I read it is, for every 2 seconds of time elapsed the output increases by 3 volts. However the voltage won't increase until 2 full seconds have elapsed. If this is correct then: (INT(input_time/2)X2)X1.5=voltage_output

commented: Correct....... +3

You are reading too much into the problem. It doesn't say to increase the voltage every 2 seconds.

So if a user inputs 5 seconds, it should display 6 volts. If a user inputs 9 seconds, it should display 12 volts.

In 5 seconds, 2 secs come twice, so 2x3+1x0=6......
In 9 seconds, 2 secs comes four times, so 4x3+1x0=12.....
Right???

Well! I think others got the wrong idea here.......

For you this can help

``````{
int n=(time/2) \\Just to make sure that n doesn't take floats.
voltage=n*3; \\Where voltage is the required output, and time is the value that you input....
cout<<voltage;

}
``````

I think that should do it......

for 5 secs, n=2, so voltage=2x3=6.....
for 9 secs, n=4, so voltage=4x3=12...
That was easy enough....

The way I read it is, for every 2 seconds of time elapsed the output increases by 3 volts. However the voltage won't increase until 2 full seconds have elapsed. If this is correct then: (INT(input_time/2)X2)X1.5=voltage_output

YES! That seems to be the case.......