Question

int main() { int a, Band3 = 0, Band1, Band2, b, c = 1; float t;...

int main() { int a, Band3 = 0, Band1, Band2, b, c = 1; float t; while (c) { Band3 = 0; printf(" Enter Resistance Value: "); scanf_s("%d", &a); printf("\n Enter Tolerance Value: "); scanf_s("%f", &t); b = t * 100; while (a % 10 == 0) { Band3++; a = a / 10; } Band2 = a % 10; a = a / 10; Band1 = a % 10; printf("\n Band1 = %d, Band2 = %d, Band3 = %d \n", Band1, Band2, Band3); if (Band3 <= 9 && a <= 9000000 && a >= 1) { switch (Band1)//this will print colour of first band { case 0: printf("black "); break; case 1: printf("Brown "); break; case 2: printf("Red "); break; case 3: printf("Orange "); break; case 4: printf("Yellow "); break; case 5: printf("Green "); break; case 6: printf("Blue "); break; case 7: printf("Voilet "); break; case 8: printf("Gray "); break; case 9: printf("White "); break; } switch (Band2)//this will print colour of second band { case 0: printf("black "); break; case 1: printf("Brown "); break; case 2: printf("Red "); break; case 3: printf("Orange "); break; case 4: printf("Yellow "); break; case 5: printf("Green "); break; case 6: printf("Blue "); break; case 7: printf("Voilet "); break; case 8: printf("Grey "); break; case 9: printf("White "); break; } switch (Band3)//this will print colour of third band { case 0: printf("black"); break; case 1: printf("Brown"); break; case 2: printf("Red"); break; case 3: printf("Orange"); break; case 4: printf("Yellow"); break; case 5: printf("Green"); break; case 6: printf("Blue"); break; case 7: printf("Voilet"); break; case 8: printf("Gray"); break; case 9: printf("White"); break; } printf("\n With tolerance=%0.2f colour is ", t); switch (b) { case 100: printf("Brown"); break; case 200: printf("Red"); break; case 50: printf("Green"); break; case 25: printf("Blue"); break; case 10: printf("Voilet"); break; case 5: printf("Grey"); break; case 500: printf("Gold"); break; case 1000: printf("Silver"); break; case 2000: printf("None"); break; } } else{//prints if value is more than 9000000 printf(" Entered wrong value "); } printf(" Enter 1 to continue: "); scanf_s("%d", &c); } }

it works fine, but it can't calculate from 1 up to 10. On other mean, when I enter resistance value from 1-10 it says a wrong value and it puts on that value in Band2 otherwise Band1. Please help me to fix it

Write a simple C/C++ console application that will print the color code of a resistor based on its entered value. Upon execution, the program will request the resistance value then tolerance then determine and print out the color codes for the resistor. On completion, the program will ask if another execution is requested otherwise the program will exit. The program should handle resistances within the range 9000000 ‐ 1 ohm and provide error handling for incorrect input. The program must contain a Switch/Case statement. Hint: Handle the multiplier first.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

updated code please now check it

#include<stdio.h>

#include<conio.h>

int main()

{

int a, Band3 = 0, Band1, Band2, b, c = 1,res;

float t;

while (c==1)

{

Band3 = 0; printf(" Enter Resistance Value: ");

scanf_s("%d", &a);

res=a;

printf("\n Enter Tolerance Value: ");

scanf_s("%f", &t);

b = t * 100;

while (a % 10 == 0)

{ Band3++; a = a / 10; }

Band2 = a % 10; a = a / 10;

Band1 = a % 10;

printf("\n Band1 = %d, Band2 = %d, Band3 = %d \n", Band1, Band2, Band3);

if (Band3 <= 9 && (res <= 9000000 && res >=1 ))

{

switch (Band1)//this will print colour of first band

{

case 0:

printf("\nBlack ");

break;

case 1:

printf("Brown ");

break;

case 2:

printf("Red ");

break;

case 3:

printf("Orange ");

break;

case 4:

printf("Yellow ");

break;

case 5:

printf("Green ");

break;

case 6:

printf("Blue ");

break;

case 7:

printf("Voilet ");

break;

case 8:

printf("Gray ");

break;

case 9:

printf("White ");

break;

}

switch (Band2)//this will print colour of second band

{

case 0:

printf("Black ");

break;

case 1:

printf("Brown ");

break;

case 2:

printf("Red ");

break;

case 3:

printf("Orange ");

break;

case 4:

printf("Yellow ");

break;

case 5:

printf("Green ");

break;

case 6:

printf("Blue ");

break;

case 7:

printf("Voilet ");

break;

case 8:

printf("Grey ");

break;

case 9:

printf("White ");

break;

}

switch (Band3)//this will print colour of third band

{

case 0:

printf("Black");

break;

case 1:

printf("Brown");

break;

case 2:

printf("Red");

break;

case 3:

printf("Orange");

break;

case 4:

printf("Yellow");

break;

case 5:

printf("Green");

break;

case 6:

printf("Blue");

break;

case 7:

printf("Voilet");

break;

case 8:

printf("Gray");

break;

case 9:

printf("White");

break;

}

printf("\n\nWith tolerance=%0.2f colour is ", t);

switch (b)

{

case 100:

printf("Brown");

break;

case 200:

printf("Red");

break;

case 50:

printf("Green");

break;

case 25:

printf("Blue");

break;

case 10:

printf("Voilet");

break;

case 5:

printf("Grey");

break;

case 500:

printf("Gold");

break;

case 1000:

printf("Silver");

break;

case 2000:

printf("None");

break;

}

}

else

{//prints if value is more than 9000000

printf("\n\nEntered wrong value ");

}

printf("\n\nEnter 1 to continue: ");

scanf_s("%d", &c);

}

}

output

RegisterColorCode- Microsoft Visual Studico Quick Launch (Ctrl+Q) BLE EDIT YIEW PROJECT BUILD DEBUG TEAM SQL İOOLS TEST ARCHITECTURE ANALYZE WNDOw HELP 0 , a a .2 Local Windows Debugger, Debug Solution Explorer (Global Scope) include< (Ctril+) Eint main( Enter Resistance Value: 16 Enter Tolerance Value: 5.0 Band1-, Band2 1, Band3 1 isterColorCode 1project) int a float while Dependencies Files Files Files Black Brown Brown e.c ith tolerance-5.00 colour is Gold eam Explorer Class View Enter 1 to continue: 1 Enter Resistance Value: 5 Enter Tolerance Value: 0.25 Band1-e, Band2 5, Band3 Black Green Black 100 % ith tolerance-0.25 colour is Blue main False False Falsc False False int Output Enter 1 to continue: Show output from 1) Bull 1> Source.c 1> Registerc Error List O Type here to search ENG 21:33 24-09-2018 54if you have any query regarding the code plase ask me in the commmet i am here for help. thank you.

Add a comment
Know the answer?
Add Answer to:
int main() { int a, Band3 = 0, Band1, Band2, b, c = 1; float t;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Figure 1(a) shows a combination of series and parallel circuit while Table 1 lists the colour...

    Figure 1(a) shows a combination of series and parallel circuit while Table 1 lists the colour code of 4-band resistor. The voltage source, vs is indicated in Figure 1(b). (a) Find the nominal value of resistor Rand the range of its actual resistance. (2 marks) (b) Using the nominal value of RL, compute the effective voltage across Rt. (6 marks) (c) Using the nominal value of Ru, calculate the average power dissipated in RL. (2 marks) 350 22 ş 150...

  • Q1. Find measurement of resistors: Resistor 1: blue - violet - black - orange - gold...

    Q1. Find measurement of resistors: Resistor 1: blue - violet - black - orange - gold Resistor 2: orange-orange-brown-brown-red Resistor 3: orange-orange - red -red-gold Resistor 4: blue - violet - red - brown - gold Resistor 5: yellow - red - brown-brown-silver Q2. What color code designates: 52, 10% Color Black Brown Red Orange Yellow Green Blue Violet Digit Multiplier Tolerance (%) 0 10° (1) 1 L 10 2 10% 3 103 4 104 5 10 0.5 6 0.25...

  • Hello, Can you answer the following question using the charts and picture I've provided? Thank You...

    Hello, Can you answer the following question using the charts and picture I've provided? Thank You so Much! Information Needed to Solve the Question (2) The two resistors, Ri and R2, shown at the top of Figure 3(a) will be used in Experımehl i. Using the colour code in Table 1, write the corresponding colour and the digit in the t below for each resistor. See the example in Figure 10. Record the values of Ri and R2 with their...

  • Three resistors with color codes 1. Brown, Brown, Brown, 2. Red, Red, Red 3. Orange, Black,...

    Three resistors with color codes 1. Brown, Brown, Brown, 2. Red, Red, Red 3. Orange, Black, Orange are connected in parallel. A battery of voltage 4.5 V is connected to the resistors. a) Draw the circuit diagram. b) List the values of the resistors according to color code. c) Calculate the equivalent resistance 1st Digit d) Find the current through each resistor e) Add the currents through each resistor to find the total current and use the voltage to find...

  • The following code must be written and run with no errors in java eclipse Description of...

    The following code must be written and run with no errors in java eclipse Description of the code to be written: A resistor is an electronic part colour-coded with three coloured bands to indicate its resistance value. This program returns the resistance of a Resistor object instantiated with three Strings, representing the three colour bands of a real resistor. Start by creating an abstract class 'AbstractResistor' that implements the Comparable interface. This class should have the following three private methods:...

  • 1. Fill in the resistance values for the following color codes: a) blue gray red silver...

    1. Fill in the resistance values for the following color codes: a) blue gray red silver b) yellow purple brown gold c) brown orange green gold d) white black orange gold e) green blue yellow silver f) red green black gold 2. Fill in the circle with the correct type of meter (V, A,2) a) b) c) 3. Which meter(s) will measure the total current in the circuit shown below? A C, D &E (circle correct answer) A & B...

  • Please help me with this question! It is due by midnight! I'm doing this in Visual...

    Please help me with this question! It is due by midnight! I'm doing this in Visual Studio 2019. But any others are fine as long as it can compile. I also wanted to see the results if it is compiled and QT comments as well. Please respond immediately! Description: For this homework we will use classes to model something in the real world. In this case a resistor. The colored bands on the top-most resistor shown in the photo below...

  • Please help. Part 3: Using the color coding for resistors, determine the resistance and the tolerance...

    Please help. Part 3: Using the color coding for resistors, determine the resistance and the tolerance for the following 3 resistors: exornn Rbolor coding: brown, black, yellow, gold Rgcolor coding: red, violet, orange, gold Rocolor coding: orange, orange, orange, gold The chage nowng thonuh a sece is every themes Find out the outest throsgh the sistance is diven e well se the colot code fur esch of the resistors 4-Band-Code 2%, 5%, 10% 560k Ω 5% 1ST BAND | 2ND...

  • 13) The value of the resistance R1 of colors (Red, Black, Black, and Gold) is: Red...

    13) The value of the resistance R1 of colors (Red, Black, Black, and Gold) is: Red Black Gold Gold: 5% Silver 1023 (A) (2052) 22 (B) (20:1) (C) (200+ 10) 2 (D) (2007 20) 2 (E) (27 0.1) Black: 0 Brown: 1 Red: 2 Orange : 3 Yellow : 4 Green: 5 Blue : 6 Violet:7 Gray: 8 White: 9 14) Which of the following equations is correct when applying Kirchhoff loop rule for the circuit shown below (A) 6...

  • Need #8 attached a cleared picture of the graph Nomina Measured Part 1: Loop Method- Calculations...

    Need #8 attached a cleared picture of the graph Nomina Measured Part 1: Loop Method- Calculations Ri 13. 3. Determine the nominal resistance and tolerance of each resistor by reading its color code. They should have the following approximate resistances: (5 pts) R1-10 Ω R2-12Ω 3 R 22 R4 = 18 Ω R-22 Ω 4. Measure the resistance of each resistor using an ohm- meter. (5 pts) 5. Measure e of the two batteries using a voltmeter They should be...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT