Training method Ampere
Perform an analysis and investigate how to calculate the following:
Given a current in Amps and a voltage in Volts, what is the value of the resistance (in Ohms) over which that voltage falls (and that current flows through)?
(Ohm’s law)
Write a program that satisfies the following requirements:
- The user can enter the voltage in V and the current in A, and your program stores those two values in two variables. The user can enter 5.5 for a voltage of five and a half volts (use type decimal for the values of voltage and current).
- Write code that calculates the value of resistance and stores that value in a third variable.
- Write code that shows the value of the third variable as “The resistance is 1234.65 ohms.”
- If your program now works then you need to transfer the code you wrote to a new method. The method looks like this:
decimal Resistance(decimal volts, decimal amps)
{
// put your own code in place of this line!
}
You’ve already written the fill-in code, move that existing code. In doing so, change the names of the variables if you wish.
- Call the Resistance method and test your program.