Thread: C program for serial and parallel resistors

  1. #1
    Registered User
    Join Date
    Nov 2017
    Posts
    4

    Exclamation C program for serial and parallel resistors

    Hello,

    I'm working on a program to calculate the total resistor of a network of resistors. In this program I have to ask the user how many resistors are serial and how many are parallel. Until that part it goes quite well, but I'm having trouble with the part where I connect the answer of the user to how often the program goes through my loop.

    I tried to make it work with a for and a while loop but I can't figure it out.

    Code:
    //Programma voor het berekenen van de vervangingsweerstand van een laddernetwerk van weerstanden.#include <stdio.h>
    #include <math.h>
    
    
    float Rvserial;
    float Rvparallel;
    float Rs, Rp;
    float totalserial, totalparallel;
    
    
    
    
    void main(void)
    {
        printf("In this program will calculate the total resistor of your network\n");
        printf("How many serialresistors do you have?\t");
        scanf("%f", &totalserial);
        printf("How many prallelresistors do you have?\t");
        scanf("%f", &totalparallel);
    
    
        while (Rs >= 0) {
            printf("Enter your values of the serial resistors. Negative value is stop\n");
            printf("Give the value in ohms\t\t");
            scanf("%f", &Rs);
            if (Rs >= 0) {
                Rvserial = Rvserial + Rs;
            }
        }
        printf("Enter your values of the parallel resistors. Negativ value is stop.\n");
        printf("Give the value in ohms \t\t");
        scanf("%f", &Rp);
        if (Rp >= 0){
            Rvparallel =
    This is what I have for now. As you can see it is far from finished and I have certain things with no use in combination with other lines, but that is just my mind at the moment.

    I hope someone can give me a clear vision.

  2. #2
    Registered User
    Join Date
    Jun 2017
    Posts
    88
    Your #include <stdio.h> is commented out. Rs has no value when it enters the while condition. Rvserial has no value when it enteres the += assignment. Rvparallel assignment has no right hand value. If statement on line 33 has no closing brace. main has no closing brace.
    Last edited by jack jordan; 11-03-2017 at 10:10 AM.

  3. #3
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    948

  4. #4
    Registered User
    Join Date
    Nov 2017
    Posts
    4
    Yes okay I know my code is off, so forget my incorret code for a moment. I want that the program gets a number from the user, this is how many serial resistors there are. If for instance that number were 4, then I want the program to ask 4 times for a value of the resistor. That single thing could be solved with an if-statement. BUT, I also want that the program gets a number from the user which refers to how many parallel resistors there are. And then it should ask how many parallel resistors there are, according to that number. And then I feel like an if-statement won't work anymore, because you have two 'unknows'.

  5. #5
    Registered User
    Join Date
    Jun 2017
    Posts
    88
    while is just a looping if statement. I don't know anything about resistors, but if you need to loop as many times as the user dictates, you can just use the user entry as your condition and decrement it ever iteration.
    Code:
    int times = 0;
    puts("Loop how many times?");
    scanf("%d", &times);
    while (times > 0) {
        // do something
        times = times - 1; // or --times;
    }
    If you are saying that you need to have variables for the user to enter data into, you could make an array to hold that data.
    Code:
    void condition() {
    	int arr[100] = { 0 };
     
    	int times = 0;
    	puts("Loop how many times?");
    	scanf("%d", &times);
    	while (times > 0) {
    		puts("Enter a number.");
    		scanf("%d", arr[times]);
    		--times;
    	}
    }

  6. #6
    Registered User
    Join Date
    Nov 2017
    Posts
    4
    Thankyou jack, I think this is what I've been looking for. For now this helps me a lot! If I have more questions, I'll come back.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Control LED by parallel port program
    By direndd in forum C++ Programming
    Replies: 3
    Last Post: 07-17-2011, 09:08 PM
  2. Serial to Parallel
    By ssharish2005 in forum Tech Board
    Replies: 11
    Last Post: 09-10-2007, 01:11 PM
  3. Replies: 2
    Last Post: 11-08-2005, 01:16 PM
  4. parallel program ideas
    By stautze in forum C Programming
    Replies: 2
    Last Post: 07-22-2002, 11:27 AM
  5. Serial-Parallel
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 04-19-2002, 04:38 AM

Tags for this Thread