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 / C++ / MFC
  4. how do i write this program?

how do i write this program?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
4 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.
  • U Offline
    U Offline
    User 12936170
    wrote on last edited by
    #1

    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..

    J P 2 Replies Last reply
    0
    • U User 12936170

      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..

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      You forgot to pass the voltage argument to printf:

      printf("Total voltage=%f V\n", voltage);

      Note also that the return value of main() is int by definition and can not be float.

      S 1 Reply Last reply
      0
      • J Jochen Arndt

        You forgot to pass the voltage argument to printf:

        printf("Total voltage=%f V\n", voltage);

        Note also that the return value of main() is int by definition and can not be float.

        S Offline
        S Offline
        Stefan_Lang
        wrote on last edited by
        #3

        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",&current);

        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)

        1 Reply Last reply
        0
        • U User 12936170

          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..

          P Offline
          P Offline
          Patrice T
          wrote on last edited by
          #4

          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

          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