这个颜色代码计算器应该以不同的颜色读取并计算阻力。
我在第54行:6:
继续收到此错误错误:声明说明符中的两个或更多数据类型
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
bool colorverify( char(*col)[7], const char(*r_col)[7]);
void resist(char (*col)[7], const char(*r_col)[7]);
void toler(char (*col)[7], const char(*r_col)[7]);
char ch;
int main(void)
{
do
{
input:;
char col[6][7];
const char r_col[11][7]={"silver","gold","black","brown","red","orange","yellow","green","blue","violet","grey","white"};
printf(" Below are is a list of color that are acceptable \n");
printf(" black brown red orange \n ");
printf(" yellow green blue violet grey \n");
printf(" white gold silver \n");
printf("\n Enter 4 band colors \n");
scanf( "%s %s %s %s ", &col[0], &col[1], &col[2], &col[3]);
if(colorverify(col, r_col))
{
resist(col, r_col);
toler(col,r_col);
}
else
{
printf("Invalid color please try again");
goto input;
}
}
while( ch=='Y' || ch =='y');
return 0;
}
/******line 54******/ bool colorverify(char(*col)[7]), const char(*r_col)[7])
{
int i, j;
bool col_valid = true;
for(j=0; j<7;j++)
{
if (!col_valid)
return false;
col_valid = false;
for(i = 0; i < 12; i++)
{
if(strncmp(col[j], r_col[i], 7) ==0)
{
col_valid= true;
break;
}
}
}
if (strncmp(col[0], r_col[2], 7) == 0) || (strncmp(col[0], r_col[1], 7)==0) || (strncmp(col[0],r_col[0], 7)== 0)
{
return false;
}
else if (strncmp(col[1], r_col[1], 7) == 0) ||(strncmp(col[1], r_col[0], 7) ==0) ||(strncmp(col[2],r_col[1], 7)==0)|| (strnc$
{
return false;
}
else if (strncmp(col[5], r_col[7], 7) ==0) ||(strncmp(col[5], r_col[10], 7) ==0) ||(strncmp(col[5],r_col[11], 7)==0)|| (strn$
{
return false;
}
else
{
return true;
}
}
void resist(char(*col)[7],const char(*r_col)[7])
{
int i;
double color_pts, resistance, exp;
for(i=0; i<4;i++)
{
if (strncmp(col[i], r_col[0],7)==0)
{
color_pts = -2;
exp= .01;
}
else if(strncmp(col[i],r_col[1],7)==0)
{
color_pts = -1;
exp= .1;
}
else if(strncmp(col[i],r_col[2],7)==0)
{
color_pts = 0;
exp= 1;
}
else if(strncmp(col[i],r_col[3],7)==0)
{
color_pts = 1;
exp= 10;
}
else if(strncmp(col[i],r_col[4],7)==0)
{
color_pts = 2;
exp= 100;
}
else if(strncmp(col[i],r_col[5],7)==0)
{
color_pts = 3;
exp= 1000;
}
else if(strncmp(col[i],r_col[6],7)==0)
{
color_pts = 4;
exp= 10000;
}
else if(strncmp(col[i],r_col[7],7)==0)
{
color_pts = 5;
exp= 100000;
}
else if(strncmp(col[i],r_col[8],7)==0)
{
color_pts = 6;
exp= 1000000;
}
else if(strncmp(col[i],r_col[9],7)==0)
{
color_pts = 7;
exp= 10000000;
}
else if(strncmp(col[i],r_col[10],7)==0)
{
color_pts = 8;
exp= 100000000;
}
else if(strncmp(col[i],r_col[11],7)==0)
{
color_pts = 9;
exp= 1000000000;
}
if(i == 0)
{
resistance= color_pts * 100;
}
if(i == 1)
{
resistance += color_pts * 10;
}
if(i == 2)
{
resistance += color_pts;
}
if(i== 3)
{
resistance = color_pts * exp;
}
if(resistance < 1000000)
{
printf(("resistance = %.2f kOhms\n"), (resistance/1000));
}
else
{
printf(("resistance = %.2f MOhms\n"), (resistance/1000000));
}
void toler(char(*col)[7], const char(*r_col)[7])
{
double tolerance;
if(strncmp(col[4], r_col[3], 7) == 0)
{
tolerance = 1;
}
else if(strncmp(col[4], r_col[3],7)==0)
{
tolerance = 2;
}
else if(strncmp(col[4], r_col[3],7)==0)
{
tolerance = 3;
}
else if(strncmp(col[4], r_col[3],7)==0)
{
tolerance = 4;
}
else if(strncmp(col[4], r_col[3],7)==0)
{
tolerance = .5;
}
else if(strncmp(col[4], r_col[3],7)==0)
{
tolerance = .25;
}
else if(strncmp(col[4], r_col[3],7)==0)
{
tolerance = .1;
}
else if(strncmp(col[4], r_col[3],7)==0)
{
tolerance = .05;
}
else if(strncmp(col[4], r_col[3],7)==0)
{
tolerance = 5;
}
else if(strncmp(col[4], r_col[3],7)==0)
{
tolerance= 10;
}
printf("Tolerance = +/- %.2f%%\n", tolerance);
}
答案 0 :(得分:1)
问题在于
void bool colorverify (char(*col)[7]), const char(*r_col)[7])
---------
//why void and bool?
void
和bool
是两种不同的数据类型。你不应该同时使用它们。请从那里摆脱void
。你不需要[根据前瞻性声明]。