Write a program to calculate the total resistance, C/C++ Programming

Assignment Help:

Write a program to calculate the total resistance of a series or parallel circuit. The maximum number of resistors is two.

1758_Write a program to calculate the total resistance.png

  We need to decide whether the user wants the total resistance of a parallel or series circuit. Let us use scanf:
 
  
  printf("Parallel (P) or Series (S) \n\r");
  scanf("\n%c",&type);
 
Note: "\n%c" is used to remove the carriage return, when we enter in P we follow it by a carriage return i.e. 2 characters so "\n" removes the second character from the awaiting buffer. Let us Input the resistor values

  printf(" Resistor Value R1\n\r");
  scanf("%f",&r1);
  printf(" Resistor Value R2\n\r");
  scanf("%f",&r2);
 
The If statement allows us to test type

  if (type == 'p' )
    {
      rt = (r1*r2)/(r1+r2);
    }
  else
    {
      rt = r1 + r2;
    }
      
We can print out the total resistance
 
  printf("Total resistance = %5.2f\n\r",rt); 

The whole program is  
 
  include
  include
  include
  include
  include
  void main()
  {
    char prompt;
     char type ;
    float r1,r2,rt;
    printf("Parallel (P) or Series (S) \n\r");
    scanf("\n%c",&type);
    printf(" Resistor Value R1\n\r");
    scanf("%f",&r1);
    printf(" Resistor Value R2\n\r");
    scanf("%f",&r2);
    if (type == 'p') 
    {
      rt = (r1*r2)/(r1+r2);
    }
    else
    {
      rt = r1 + r2;
    }
    printf("Total resistance = %5.2f\n\r",rt);   
    printf("Press any key to exit \n\r");
    scanf("\n%c",&prompt);
    }
 
  It is worth noting that the If statement is case sensitive i.e. try 'p' instead of 'P'. Care must be taken and code should cater for upper and lower type. Considering the above program what if we want to calculate ten sets of resistor combinations, we would have to repeat this section of code ten times. Within C we have the ability to repeat sections of code using three different types of code namely:  while, do while and For statements.


Related Discussions:- Write a program to calculate the total resistance

#CompilerRelated, #C Why don''t online compilers support the header file?...

#C Why don''t online compilers support the header file? What can I do to resolve this? PS. I have tried , does''nt work either. Thannk in advance.

Calculate the area and circumference of a circle , Write a program which in...

Write a program which incorporates a function named compute and which is used to calculate the area and circumference of a circle. Use the main function for inputs and outputs.

Need cron job parsing json from api, Need Cron Job Parsing JSON from API, I...

Need Cron Job Parsing JSON from API, Inserting in to DB Project Description: The Project is to prepare a Cron Job with an adjustable interval in seconds and milli seconds. Cr

Design test program that tests the student, This is a test program that tes...

This is a test program that tests the Student and ITECH7603Class classes.     In this assignment you are provided with three input text files associated with this program:

How to implement tr- 069 protocol, Description - The TR-069 CPE WAN Managem...

Description - The TR-069 CPE WAN Management Protocol (CWMP) is a protocol that was created by the Broadband Forum (formally the DSL Forum) which sets out a common method for CPE de

LOOPS, HOW CAN WE EASLY LEARN C++

HOW CAN WE EASLY LEARN C++

Cloud computing, hi Bhasker, as we spoke tru phone ,we need a project usin...

hi Bhasker, as we spoke tru phone ,we need a project using cloud computing .we need to present a protoype or demo on it (any thing using cloud should be fine)(ex: P2p)

Algorithm, for different operation multiple stack

for different operation multiple stack

I want a reverse engineer a .exe to obtain the code, I want a Reverse engin...

I want a Reverse engineer a .exe to obtain the code Project Description: I'd like to get the full C++ source code from a .exe please Skills required is C++ Programming

Integration, Write a program to find the area under the curve y = f(x) betw...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd