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

PLEASE WRITE IN C LANGUAGE ONLY We are going to create a simple resistance calcu

ID: 3889078 • Letter: P

Question

PLEASE WRITE IN C LANGUAGE ONLY

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

PLEASE ONLY C LANGUAGE

Explanation / Answer

#include <stdio.h>

#include <math.h>

#include<string.h>

long long int lcm(long int a, long int b)

{

long long int product = a*b, temp;

while(a%b!=0)

{

temp = b;

b = a%b;

a = temp;

}

return (product/b);

}

float calculate_res(long int resistance_value[], int t, int isSeries)

{

long int result = 0, i;

if(isSeries == 1)

{

for(i=0;i<t;i++)
result = result + resistance_value[i];

return result;

}

else

{

long long int temp = 0, lcm_value = resistance_value[0];

for(i=1;i<t;i++)

{

lcm_value = lcm(lcm_value, resistance_value[i]);

}

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

{

temp = temp + lcm_value/resistance_value[0];

}

if(t>1)

return lcm_value*1.0/temp;

else

return

lcm_value;

}

}

int main(void) {

int result,i, j, isSeries = 0, t;

long long int temp=0, temp2=0;

char colorcode[100], ch = 'Y', resistance_format[20];

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

while(ch != 'N')

{

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

scanf("%s ",resistance_format);

if(strcmp(resistance_format,"Series")==0)

{

isSeries = 1;

}

else

isSeries = 0;

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

scanf("%d ",&t);

long int resistance_value[t];
temp = 0;

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

{

scanf("%s ",colorcode);

if(i!=2)

{

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

{

temp = temp * 10 + 0;

}

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

{

temp = temp * 10 + 1;

}

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

{

temp = temp * 10 + 2;

}

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

{

temp = temp * 10 + 3;

}

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

{

temp = temp * 10 + 4;

}

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

{

temp = temp * 10 + 5;

}

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

{

temp = temp * 10 + 6;

}

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

{

temp = temp * 10 + 7;

}

else if(strcmp(colorcode,"Grey")==0)

{

temp = temp * 10 + 8;

}

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

{

temp = temp * 10 + 9;

}

}

else

{

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

{

temp2 = 0;

}

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

{

temp2 = 1;

}

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

{

temp2 = 2;

}

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

{

temp2 = 3;

}

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

{

temp2 = 4;

}

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

{

temp2 = 5;

}

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

{

temp2 = 6;

}

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

{

temp2 = 7;

}

else if(strcmp(colorcode,"Grey")==0)

{

temp2 = 8;

}

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

{

temp2 = 9;

}

}

}

resistance_value[0] = temp * (pow(10,temp2));

for(i=1;i<t;i++)
resistance_value[i] = resistance_value[0];

printf("Total resistance is %.2f ",calculate_res(resistance_value, t, isSeries));

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

scanf(" %c",&ch);

//printf("ch = %c ",ch);

}

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