我正在尝试制作一个在 Windows 控制台中启动的程序,该程序会在电阻器中询问“第一个波段的颜色是什么”,因此当您键入诸如“红色”之类的内容时,它会将 2 输入到浮点数中。我遇到的问题是,我不仅不知道如何将“红色”变成“2”,而且每当我尝试在控制台上输入文本时,它都会显示其余的 printf 并跳到最后。
这就是我到目前为止所做的,我注释掉了第三和第四个输入,以便我可以更轻松地进行故障排除。
//Color bands
#include <stdio.h>
int
main(void)
{
double first;
double second;
//double third;
//double fourth;
double total_resist;
double black, brown, red = 2, orange, yellow, green, blue, violet, gray, white;
black = 0;
brown = 1;
red = 2;
orange = 3;
yellow = 4;
green = 5;
blue = 6;
violet = 7;
gray = 8;
white = 9;
printf("Input first color band> ");
scanf("%lf", &first);
printf("Input second color band> ");
scanf("%lf", &second);
total_resist = first + second;// + second + third + fourth;
printf("\nTotal resistance is %.lf\n", total_resist);
return(0);
}