Thread: How to terminate in loop? Help

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    13

    How to terminate in loop? Help

    Code:
      float i, R, I; // counter, resistance, input//
            float V; // voltage//
    
    
            printf("Enter the current: ");
            scanf("%f",&I);
    
    
    
    
    
    
            while ( R != -1) {
    
    
                     
                    printf("Enter the resistance: " );
                    scanf("%f",&R);
                    V= R * I;
                    printf("Voltage is %f\n", V);
            }
    
    
            return 0;
    The question is to write a program that will input resistance R, current I for serval resistors, and will calculate and display the voltage for each resistor. The loop will terminate if your enter -1 as the resistance value. (Note that your program should output nothing when -1 is entered as the resistance value)
    I want it to do nothing when I enter -1 for resistance but for this one it calculates the voltage. So what should i do?
    Last edited by Zijing Ky; 10-15-2012 at 02:51 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why won't this loop terminate
    By JayCee++ in forum C++ Programming
    Replies: 4
    Last Post: 10-14-2011, 10:00 AM
  2. terminate loop
    By miryellis in forum C Programming
    Replies: 3
    Last Post: 09-07-2004, 07:14 AM
  3. how to terminate for loop
    By Chobo_C++ in forum C++ Programming
    Replies: 2
    Last Post: 04-18-2004, 05:43 PM
  4. terminate 0 - PLEASE HELP
    By Unregistered in forum C Programming
    Replies: 11
    Last Post: 11-21-2001, 07:30 AM
  5. How do I terminate a FOR Loop?
    By JYoung in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 11-14-2001, 03:37 AM