Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C language: The sites mentioned are: https://www.digikey.com/en/resources/con

ID: 3870723 • Letter: I

Question

In C language:

The sites mentioned are: https://www.digikey.com/en/resources/conversion-calculators/conversion-calculator-resistor-color-code-4-band

and.

http://www.daycounter.com/Calculators/Parallel-Resistance-Calculator.phtml

We are going to create a simple resistance calculator.
Your program should:

ask the user if the resistors are in series or parallel

read in the number of resistors

read in the resistance of the individual resistors (let's assume they are all the same resistance) by having the user enter the first three colors of the 4 bands on the resistor (this site ( https://www.digikey.com/en/resources/conversion-calculators/conversion-calculator-resistor-color-code-4-band) can help with color code calculations)

calculate the total resistance of the circuit (this site (

http://www.daycounter.com/Calculators/Parallel-Resistance-Calculator.phtml

) can help with parallel resistor equations calculatons)

print out the result

Below is a sample execution of the program (values in bold are user input and should NOT be hardcoded into your program)

***
Welcome to the simple resistance calculator

Are the resistors in Series or Parallel? Series

How many resistors are there in the circuit? 5

The first three color bands on the resistors: Red Red Red

Each resistor is 2200 ohms and the total resistance of the circuit is 11000 ohms

Would you like to perform another calculation (Y/N)? Y

Are the resistors in Series or Parallel? Parallel

How many resistors are there in the circuit? 4

The first three color bands on the resistors: Red Red Red

Each resistor is 2200 ohms and the total resistance of the circuit is 550 ohms

Would you like to perform another calculation (Y/N)? N

Side note: Need help calculating resistance in each resistor.

Explanation / Answer

#include<stdio.h>

#include<string.h>

int calculate_resistance(char col1[], char col2[], char col3[], char color[10][7]);

int colour_value(char col[], char color[10][7]);

int main()

{

char color_code[10][7] = { "Black" , "Brown", "Red", "Orange", "Yellow", "Green", "Blue" };

int multiplier[7] = { 1, 10, 100, 1000, 100000, 1000000, 10000000 };

char choice[10];

char col1[10], col2[10], col3[10];

int n,i;

int resistor = 220;

enum color_code color;

int total_resistance = 0, each_resistance;

printf("Welcome to the simple resistance calculator ");

printf("Are the resistors in Series or Parallel ? ");

scanf("%s", choice);

printf("How many resistors are there in the circuit ? ");

scanf("%d", &n);

printf("The first three color bands on the resistors : ");

scanf("%s%s%s", col1, col2, col3);

each_resistance = calculate_resistance(col1, col2, col3, color_code);

if (strcmp(choice, "series") == 0 || strcmp(choice, "Series") == 0)

{

//for series circiut ,resistance is sum of the resistor values in sries,,since each resistor is same we can just multiply resistance with no of resistors

total_resistance = each_resistance *n;

}

if (strcmp(choice, "parallel") == 0 || strcmp(choice, "Parallel")== 0 )

{

//since eacch resistor is same, instead of writting 1/R = 1/R1+ 1/R2+1/R3+1/R4+1/R5, R1=R2=R3=R4=R4 if take is R,total resistance R = One resistor value/no of resistor

total_resistance = each_resistance/n;

}

printf("Each resistor is %d ohms and the total resistance of the circuit is %d ohms ", each_resistance, total_resistance);

}

int calculate_resistance(char col1[], char col2[], char col3[], char color[][7])

{

int i, col1_value ,col2_value , col3_value;

int res;

col1_value = colour_value(col1,color);

col2_value = colour_value(col2, color);

col3_value = colour_value(col3, color);

res = col1_value * 0 + col1_value * 100 + col3_value*1000;

return res;

}

int colour_value(char col[], char color[10][7])

{

int i;

for (i = 0; i < 7; i++)

{

if (strcmp(col, color[i]) == 0)

return i;

}

}

----------------------------------------------------------------------

//output1

Welcome to the simple resistance calculator
Are the resistors in Series or Parallel ? Series
How many resistors are there in the circuit ? 5
The first three color bands on the resistors :
Red Red Red
Each resistor is 2200 ohms and the total resistance of the circuit is 11000 ohms

//output2

Welcome to the simple resistance calculator
Are the resistors in Series or Parallel ? Parallel
How many resistors are there in the circuit ? 4
The first three color bands on the resistors :
Red Red Red
Each resistor is 2200 ohms and the total resistance of the circuit is 550 ohms