how do i write this program?
-
write a program to find voltage when enter current and resistor value using the following formula:voltage=current x resistor #include float main() { float current,resistor,voltage; printf("Enter the current value:"); scanf("%f",¤t); printf("Enter the resistor value:"); scanf("%f",&resistor); voltage = current*resistor; { printf("Total voltage=%2f V"); } return 0; } i try this but i cant find the correct output.. please help me..i am a student..
-
write a program to find voltage when enter current and resistor value using the following formula:voltage=current x resistor #include float main() { float current,resistor,voltage; printf("Enter the current value:"); scanf("%f",¤t); printf("Enter the resistor value:"); scanf("%f",&resistor); voltage = current*resistor; { printf("Total voltage=%2f V"); } return 0; } i try this but i cant find the correct output.. please help me..i am a student..
You forgot to pass the
voltage
argument toprintf
:printf("Total voltage=%f V\n", voltage);
Note also that the return value of
main()
isint
by definition and can not befloat
. -
You forgot to pass the
voltage
argument toprintf
:printf("Total voltage=%f V\n", voltage);
Note also that the return value of
main()
isint
by definition and can not befloat
.That, and there's some weird line, although it may just be a case of messed up copy/pasting:
scanf("%f",¤t);
should be:
scanf("%f",¤t);
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
-
write a program to find voltage when enter current and resistor value using the following formula:voltage=current x resistor #include float main() { float current,resistor,voltage; printf("Enter the current value:"); scanf("%f",¤t); printf("Enter the resistor value:"); scanf("%f",&resistor); voltage = current*resistor; { printf("Total voltage=%2f V"); } return 0; } i try this but i cant find the correct output.. please help me..i am a student..
When you don't understand what your code is doing or why it does what it does, the answer is debugger. Use the debugger to see what your code is doing. It allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool. Debugger - Wikipedia, the free encyclopedia[^] Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^] The debugger is here to show you what your code is doing and your task is to compare with what it should do. There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
Patrice “Everything should be made as simple as possible, but no simpler.” Albert Einstein