resistor colour band

Pages: 12
closed account (Nh79E3v7)
Write your question here.

can you help me to solve the coding about resistor colour band
Y
closed account (Nh79E3v7)
i don't understand about my assignments project about.....can u help me
Can you do telepathy? I can't :+(
closed account (Nh79E3v7)
can you give me your email....i wil send to you my question about my c++ project assignment
can you give me your email.


Definitely not.

Post a proper question here - the actual assignment question, with all the details, and your code so far - don't forget the code tags or any compiler errors you have.

Note we can help, but not do your assignment.
closed account (Nh79E3v7)
how i can write this formula in c++

[( 10 x 1st band ) + 2nd band ] x 3rd band ) ± 4th band %

and how i can write about the tolerance ± 4th band %.....
Post a proper question here - the actual assignment question, with all the details, and your code so far - don't forget the code tags or any compiler errors you have.
closed account (Nh79E3v7)
You are required to design a program to determine the value of a resistor based on resistor colour code. The program should prompt users to request the 4 bands colour marked on the resistor. The result should be display along with its tolerance. The user then asked whether he/she want to continue to determine the value of other resistor or not. If the user enter “Y” or “y”, the program will continue, otherwise enter “N”or “n” the program will stop. The program also should prompt an error message if the user enter an invalid colour code. Bonus marks will be given to any group that can show the correct error message in each selection of colour code.

this is my coding but i don't finish yet....plase help me....i using a function
#include<stdio.h>
#include<Windows.h>
#include<math.h>

double colour_code(double red,double yellow,double green,double silver);


int main()
{
double red,yellow,green,silver,resistance;
char conn= 'r';



while (conn !='n' || conn !='N')
{
printf("Enter connection of colour code\n Red=r\nYellow=y\nGreen=g\nSilver=s\nStop=N/n\n");

scanf("%c", &conn);

if(conn=='n' || conn=='N')
break;
else
{
printf("\nenter the value of colour code of red: ");
scanf("%lf", &red);
printf("\nenter the value of colour code of yellow: ");
scanf("%lf", &yellow);
printf("\nenter the value of colour code of green: ");
scanf("%lf", &green);
printf("\nenter the value of colour code of silver: ");
scanf("%lf", &g);



if (conn== 'r')
{
resistance=colour_code(red,yellow,green,silver);
printf("Result is %lf\n",resistance);


}


else
{
printf("invalid operator\n");

}
getchar();

}



}

//return(0);
system("pause");
}
double colour_code(double red,double yellow,double green,double silver)
{
double resistance;
char red=2,yellow=4,green=100000;
resistance = (10*red + yellow) * green



}
How to use tags: http://www.cplusplus.com/articles/z13hAqkS/

Show your compiler errors / warnings - paster them here.

I don't think you have shown the complete assignment: where does it talk about the tolerances formula you hinted at earlier? Ideally post the whole assignment text as your received it.

There is a tutorial at the top left of this page.

How does one return a value from a function?

What should one do to see that the call to scanf worked?

The program also should prompt an error message if the user enter an invalid colour code. Bonus marks will be given to any group that can show the correct error message in each selection of colour code.


Where is the information about these colour codes?

I hope this helps a little, but you really need to be less vague.

It's late at my end, so I may not reply until tomorrow.
closed account (Nh79E3v7)
Project Title: Resistor Calculator Resistor is an electrical component that reduces an electric current. The resistor's ability to reduce current is called resistance and is measured in units of ohms, Ω. The resistance of a resistor and its tolerance are marked on the resistor by color bands that denotes the resistance value as shown in Figure 1. Table 1 shows the value of each colour band.


Figure 1: Resistor colour band.


Table 1: Digit, multiplier and tolerance band chart. Colour 1st Band 2nd Band 3rd Band (Multiplier) 4th Band (Tolerance) Black 0 0 1 Brown 1 1 10 Red 2 2 100 Orange 3 3 1 000 Yellow 4 4 10 000 Green 5 5 100 000 Blue 6 6 1 000 000 Violet 7 7 10 000 000 Grey 8 8 100 000 000 White 9 9 1 000 000 000 Gold ±5% Silver ±10% None ±20%



You are required to design a program to determine the value of a resistor based on resistor colour code. The program should prompt users to request the 4 bands colour marked on the resistor. The result should be display along with its tolerance. The user then asked whether he/she want to continue to determine the value of other resistor or not. If the user enter “Y” or “y”, the program will continue, otherwise enter “N”or “n” the program will stop. The program also should prompt an error message if the user enter an invalid colour code. Bonus marks will be given to any group that can show the correct error message in each selection of colour code.



Example calculation By referring to Figure 1, the colour band of the resistor is as follow: 1st band : Red --------> 2 2nd band : Yellow ----> 4 3rd band : Green -----> 100 000 4th band : Silver ------> ±10% Thus, its resistance value is : Formula : [( 10 x 1st band ) + 2nd band ] x 3rd band ) ± 4th band % Resistance = [ (10 x 2 + 4) x 100 000] ±10% = 2 400 000 Ω ±10%
You going about this the wrong way. You have to prompt the user for the color of each band.
You're asking the user for the value of red, yellow, green, etc. Those are known.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

const char * colors[10] = { "black", "brown", "red", "orange", "yellow",
                            "green", "blue", "violet", "grey", "white" };

int get_band (int n)
{   char input[10];
    
    printf ("Enter color of band# %d: " , n+1);
    scanf ("%s", input);
    for (int i=0; i<10; i++)
    {   if (strcmp(input, colors[i]) == 0)
          return i;           
    }
    printf ("Invalid input\n");
    exit (1); 
}    
                            
int main()
{   int band[3];
    long value;
                                  
    for (int i=0; i<3; i++)
        band[i] = get_band(i);
    value = band[0] * 10 + band[1];
    value *= (long)pow(10.0, (double)band[2]);
    printf ("The value of that resistor is %ld ohms\n", value);
    system("pause");
    return 0;
}


I will leave the tolerance band and repetition to you.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Last edited on
closed account (Nh79E3v7)
i want to use a function.....because i must to present it to lecturer
hmm....what that u used it??
get_band() is a function.

Make sure you understand what I provided and don't blindly present it to your lecturer.
That's the same code you posted before.

i don't understand about it.

What don't you understand?

can u do in basic function only

I don't know what you mean by "basic function". I gave you a working example using a function.

You have been asked to use code tags. PLEASE DO SO.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
If you're not going to make the slightest bit of effort to make your posts readable, why should we spend the slightest bit of effort helping you?
I will not respond further until you apply code tags.
closed account (Nh79E3v7)
can u explain for me about the code that u gave for me last night.....i want to understand it and how about a tolerance value and repetition......why we must to use a repetition
closed account (Nh79E3v7)
how i want to take a tolerence value in my code....i don't understand about it.....and how i can take a If the user enter “Y” or “y”, the program will continue, otherwise enter “N”or “n” the program will stop.
how i want to take a tolerence value in my code

Look at lines 9-20 (function get_band) of the code i posted above. That code converts a color name from a string to a numeric value. Dealing with the tolerance band is no different, except the colors are different and the values are percentages rather than a simple index.

and how i can take a If the user enter “Y” or “y”, the program will continue

You had such a loop in your original program.

Last edited on
closed account (Nh79E3v7)
can you do it for me.....i can't think about it anymore......please....i need to prepare it tomorrow...
can you do it for me


No, we said we wouldn't. AbstractionAnon has given you huge help, probably more than you deserve.

.i can't think about it anymore......please....i need to prepare it tomorrow..


That's too bad. Whining won't help.

Sorry if I sound harsh, but I get the distinct impression that your intention all along was for someone to do it for you.
Pages: 12