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

PLEASE WRITE IN C LANGUAGE: We are going to create a simple resistance calculato

ID: 3870744 • Letter: P

Question

PLEASE WRITE IN C LANGUAGE:

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 can help with color code calculations). ( https://www.digikey.com/en/resources/conversion-calculators/conversion-calculator-resistor-color-code-4-band)

calculate the total resistance of the circuit (this site can help with parallel resistor equations calculatons).

(

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

)

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

PLEASE WRITE IN C LANGUAGE:

Explanation / Answer

//Working solution for above prolem

#include<stdio.h>

#include<conio.h>

double getResistance(char c1[], char c2[], char c3[]){

int digit1 = getColorValue(c1);

int digit2 = getColorValue(c2);

int number = digit1 * 10 + digit2;

//get power of 10 for multiplier

int power = getColorValue(c3);

//get multiplier

double multiplier = 1.0;

//for Gold

if(power == -1){

multiplier = 0.1;

}

//for silver

else if(power == -2){

multiplier = 0.01;

}

//for all other colors

else{

int i;

for(i = 0; i < power; i++){

multiplier = multiplier * 10;

}

}

//final resistnace

int resistance = number * multiplier;

}

int getColorValue(char str[]){

if (strcmp(str, "Black") == 0)

{

return 0;

}

else if (strcmp(str, "Brown") == 0)

{

return 1;

}

else if (strcmp(str, "Red") == 0)

{

return 2;

}

else if (strcmp(str, "Orange") == 0)

{

return 3;

}

else if (strcmp(str, "Yellow") == 0)

{

return 4;

}

else if (strcmp(str, "Green") == 0)

{

return 5;

}

else if (strcmp(str, "Blue") == 0)

{

return 6;

}

else if (strcmp(str, "Violet") == 0)

{

return 7;

}

else if (strcmp(str, "Gray") == 0)

{

return 8;

}

else if (strcmp(str, "White") == 0)

{

return 9;

}

else if (strcmp(str, "Gold") == 0)

{

return -1;

}

else if (strcmp(str, "Silver") == 0)

{

return -2;

}

// invalid resistance

else

{

return -100;

}

}

int main(){

  

char cont = 'Y';

while(cont == 'Y'){

char position[20], c1[20], c2[20], c3[20];

int num = 0;

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

scanf("%s", position);

printf(" Number of resistors : ");

scanf("%d", &num);

printf(" Enter 1st color : ");

scanf("%s", c1);

printf(" Enter 2nd color : ");

scanf("%s", c2);

printf(" Enter 3rd color : ");

scanf("%s", c3);

double resistance = getResistance(c1, c2, c3);

printf(" Each Resistance value is %f ", resistance);

if(strcmp(position,"Series") == 0){

resistance = resistance * num;

}else{

resistance = resistance / num;

}

printf("Total resistance of circuit is %f ", resistance);

printf("Do you want to perform another calculation (Y/N)? : ");

fflush(stdin);

scanf("%c", &cont);

}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote