按照书上来的 不知道怎么弄了 #include<stdbool.h> 无效
//program 5.6 know your hat size-if you dare...#include<stdio.h>
int main(void)
{
char size[3][12]={
{'6','6','6','6','7','7','7','7','7','7','7','7'},
{'1','5','3','7',' ','1','1','3','1','5','3','7'},
{'2','8','4','8',' ','8','4','8','2','8','4','8'}
};
int head_size[12]=
{164,166,169,172,175,178,181,184,188,191,194,197};
float cranium=0.0f;
int your_head=0;
bool hat_found=false;
//get the circumference of the head
printf("\nenter the circumference of your head above your eyebrows"
"in inches as a decimal value:");
scanf(" %f",&cranium);
your_head=(int)(8.0f*cranium);
size_t i=0;
if(your_head==head_size[i])
hat_found=true;
else
{
for(i=1;i<sizeof(head_size);++i)
{
//find head size in the headsize array
if(your_head>head_size[i-1]&&your_head<=head_size[i])
{
hat_found=true;
break;
}
}
}
if(hat_found)
{
printf("\nyour hat size is %c %c%c%c\n",size[0][i],size[1][i],(size[1][i]==' ')?' ':'/',size[2][i]);
}
else
{
if(your_head < head_size[0])
printf("\nyou are the proverbial pinhead.no hat for you I'm afraid.\n");
else
printf("\nyou,in technical parlance,are a fathead.no hat for you,I'm afraid.\n");
}
return 0;
} 输入范围以外的数,不显示所要显示的内容。 用的v c++6.0,输入 #include<stdbool.h> 不支持?if(hat_found) 读不出 bool hat_found=false;