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

Problem Description The Lab coordinator asked you to create a program that helps

ID: 671546 • Letter: P

Question

Problem Description

The Lab coordinator asked you to create a program that helps them set up a circuits lab practices using the smallest number of resistors. We have three types of resistors 1 ohms, 5 ohms resistors and 15 ohms. We want to build resistors in series to match a target resistance value. When a number of resistors are connected in series, then the total resistance is the sum of their values.  

What to do

Write a program that repeatedly asks the user for the target resistance value and determines the minimum number of resistors needed to reach the target resistance value and shows the number of each resistor type we need to reach the target. When the program finishes computing one target value, the user is given the option to input another.

The program output looks something like this:

Explanation / Answer

#include <iostream>

using namespace std;

int main()

{

  

int resistance,count15,count1,count5;

char choice;

  

while(true)

{

cout << "What is the target resistance value : ";

cin >> resistance;

  

count15 = resistance/15;

resistance = resistance%15;

  

count5 = resistance/5;

resistance = resistance%5;

  

count1 = resistance;

  

resistance = 0;

  

cout << "You need a minimum of " << count1+count15+count5 << " resistors." << endl;

cout << "Resistors needed: ";

  

cout << count15 << " X " << "15 ohms." << endl;

cout << count5 << " X " << "5 ohms." << endl;

cout << count1 << " X " << "1 ohm." << endl;

  

cout << "Would you like to compute another resistance value? Y or N : ";

cin >> choice;

  

if(choice == 'Y' || choice == 'y')

continue;

else

break;

}

  

cout << " Goodbye! ";

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