这个题目是,用数组计算帽子的尺寸,只需输入帽子的周长,然后显示帽子的尺寸
(谢谢大家啦~这个问题已经解决啦。。。)
#include "stdio.h"
typedef unsigned char bool
#define true 1
#define false 0
main() //在这里出现的问题。。说明语法错误。。请教各位高手要如何修改
{
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 headsize[12] = {164,166,169,172,178,181,184,188,191,194,197};
float cranium = 0.0;
int your_head = 0;
int i = 0;
bool hat_found = false;
printf("\nEnter the circumference of your head above your eyebrows"
"in inches as a decimal value: ");
scanf("%f",&cranium);
your_head = (int)(8.0*cranium);
for(i=1;i<12;i++)
{
if(your_head > headsize[i-1] && your_head <= headsize)
{
hat_found = true;
break;
}
if(your_head == headsize[0])
{
i = 0;
hat_found = true;
}
if(hat_found)
printf("\nyour hat size is %c %c%c%c\n",
size[0][1],size[1],(size[1]==' ')? ' ' : '/',size[2]);
else
{
if(your_head < headsize[0])
printf("\nyou are the proverbial pinhead. no hat for you i'm afraid.\n");
else
printf("\nyou,in technical parlance,are a fathead.");
}
return 0;
}
}
我用的编译器是 Turbo C ...在编写代码的时候。。。主函数只用main()这么写就可以了呢。。
[ 本帖最后由 cristin871125 于 2009-5-28 14:11 编辑 ] |