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.
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.
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>
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);
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.
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.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
constchar * 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.
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.
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
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.
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