C 计算电阻值的色带并输出
忽略电阻公差 这是我的密码 输出必须类似于 我下面的代码没有给出我想要的。我希望它能够循环返回y和no。输出必须分开{3}{3}C 计算电阻值的色带并输出,c,C,忽略电阻公差 这是我的密码 输出必须类似于 我下面的代码没有给出我想要的。我希望它能够循环返回y和no。输出必须分开{3}{3} I'm trying to develop a C program that calculates the resistor values by inputting the colour bands marked on the resistor. #包括 #包括 #包括 #包括 #包括 int波段选择; 炭色酮[10]; 2[10]; 三[10]; 浮动码元; 浮动
I'm trying to develop a C program that calculates the resistor values by inputting the colour bands marked on the resistor.
#包括
#包括
#包括
#包括
#包括
int波段选择;
炭色酮[10];
2[10];
三[10];
浮动码元;
浮动代码2;
浮动代码3;
浮动x;
无效颜色代码();
无效乘数();
无效颜色代码(字符代码);
内部主(空)
{printf(“输入电阻器三个波段的颜色,从最靠近末端的波段开始。仅以小写字母键入颜色,不使用大写字母\n”);
认沽权(“”);
printf(“波段1=>”;
扫描频率(“%s”,彩色);
认沽权(“”);
printf(“波段2=>”;
扫描频率(“%s”,彩色二);
认沽权(“”);
printf(“波段3=>”;
扫描频率(“%s”,彩色三);
认沽权(“”);
printf(“%f%f%f\n”,颜色一、颜色二、颜色三);
x=(编码一*10)+编码二;
printf(“电阻值%d”);
}
无效颜色代码(字符代码)
{
如果(strcmp(彩色,“黑色”)==0)
{
可待因=0;
}
其他的
如果(strcmp(彩色,“棕色”)==0)
{
可待因=1;
}
其他的
如果(strcmp(彩色,“红色”)==0)
{
可待因=2;
}
其他的
如果(strcmp(彩色,“橙色”)==0)
{
可待因=3;
}
其他的
如果(strcmp(彩色,“黄色”)==0)
{
可待因=4;
}
其他的
如果(strcmp(彩色,“绿色”)==0)
{在这里输入代码
可待因=5;
}否则
如果(strcmp(彩色,“蓝色”)==0)
{
可待因=6;
}否则
如果(strcmp(彩色,“紫色”)==0)
{
可待因=7;
}否则
如果(strcmp(彩色,“灰色”)==0)
{
可待因=8;
}否则
如果(strcmp(彩色,“白色”)==0)
{
可待因=9;
}否则
{
printf(“无效颜色\n”);
}
}
无效乘数()
{
如果(strcmp(三色,“黑色”)==0)
{
代码三=1;
}否则
如果(strcmp(颜色三,“棕色”)==0)
{
代码3=10;
}否则
如果(strcmp(三色,“红色”)==0)
{
代码三=功率(10.0,2);
}否则
如果(strcmp(颜色三,“橙色”)==0)
{
代码三=功率(10.0,3);
}否则
如果(strcmp(颜色三,“黄色”)==0)
{
代码三=功率(10.0,4);
}否则
如果(strcmp(三色,“绿色”)==0)
{
代码三=功率(10.0,5);
}否则
如果(strcmp(颜色三,“蓝色”)==0)
{
代码三=功率(10.0,6);
}否则
如果(strcmp(三色,“紫色”)==0)
{
代码三=功率(10.0,7);
}否则
如果(strcmp(颜色三,“灰色”)==0)
{
代码三=功率(10.0,8);
}否则
如果(strcmp(三色,“白色”)==0)
{
代码三=功率(10.0,9);
}否则
{
printf(“无效颜色\n”);
}
}
http://imgur.com/rya9egk
如果有人能帮忙,我真的很感激
color\u code
功能设计不正确。您应该输入颜色字符串并返回代码字符串color\u code
函数colorOne
colorTwo
colorthree
codeOne
codeTwo
codeThree
可以设置为本地到主控,而不是全局color\u code
功能设计不正确。您应该输入颜色字符串并返回代码字符串color\u code
函数colorOne
colorTwo
colorthree
codeOne
codeTwo
codeThree
可以设置为本地到主控,而不是全局我想让您看看
enum
常量是如何在中使用的。这将大大简化将颜色代码与电阻值关联起来的工作,从而将使用的颜色代码和电阻值相加,得到总电阻值。您可以自由使用或修改您在那里找到的代码。我值得您花点时间看看enum
常量是如何在中使用的。这将大大简化将颜色代码与电阻值关联起来的工作,从而将使用的颜色代码和电阻值相加,得到总电阻值。您可以自由地使用或修改在那里找到的代码。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
int bandChoice;
char colorOne[10];
char colorTwo[10];
char colorThree[10];
float codeOne;
float codeTwo;
float codeThree;
float x;
void colorCodes();
void multiplier();
void color_code(char codeOne);
int main(void)
{ printf("Enter the colors of the resistor three bands, beginning with the band nearest the end. Type the colors in lowercase letters only, NO CAPS\n");
puts(" ");
printf("Band 1 = >");
scanf("%s",colorOne);
puts(" ");
printf("Band 2 = >");
scanf("%s",colorTwo);
puts(" ");
printf("Band 3 = >");
scanf("%s",colorThree);
puts(" ");
printf("%f %f %f\n",colorOne,colorTwo,colorThree);
x=(codeOne*10)+codeTwo;
printf("Resistance value %d");
}
void color_code(char codeOne )
{
if(strcmp(colorOne, "black") == 0)
{
codeOne=0;
}
else
if(strcmp(colorOne, "brown") == 0)
{
codeOne=1;
}
else
if(strcmp(colorOne, "red") == 0)
{
codeOne=2;
}
else
if (strcmp(colorOne, "orange") == 0)
{
codeOne=3;
}
else
if (strcmp(colorOne, "yellow") == 0)
{
codeOne=4;
}
else
if (strcmp(colorOne, "green") == 0)
{enter code here
codeOne=5;
} else
if (strcmp(colorOne, "blue") == 0)
{
codeOne=6;
} else
if (strcmp(colorOne, "violet") == 0)
{
codeOne=7;
} else
if (strcmp(colorOne, "gray") == 0)
{
codeOne=8;
} else
if (strcmp(colorOne, "white") == 0)
{
codeOne=9;
} else
{
printf("Invalid colors\n");
}
}
void multiplier()
{
if(strcmp(colorThree, "black") == 0)
{
codeThree=1;
} else
if(strcmp(colorThree, "brown") == 0)
{
codeThree=10;
} else
if(strcmp(colorThree, "red") == 0)
{
codeThree=pow(10.0,2);
} else
if (strcmp(colorThree, "orange") == 0)
{
codeThree=pow(10.0,3);
} else
if (strcmp(colorThree, "yellow") == 0)
{
codeThree=pow(10.0,4);
} else
if (strcmp(colorThree, "green") == 0)
{
codeThree=pow(10.0,5);
} else
if (strcmp(colorThree, "blue") == 0)
{
codeThree=pow(10.0,6);
} else
if (strcmp(colorThree, "violet") == 0)
{
codeThree=pow(10.0,7);
} else
if (strcmp(colorThree, "gray") == 0)
{
codeThree=pow(10.0,8);
} else
if (strcmp(colorThree, "white") == 0)
{
codeThree=pow(10.0,9);
} else
{
printf("Invalid colors\n");
}
}
http://imgur.com/rya9egk
char color_code(char *colorOne )
{
char codeOne;
if(strcmp(colorOne, "black") == 0)
{
codeOne=0;
}
// and so on for other colors
// at the end
return codeOne;
}
codeOne = color_code(colorOne);