当前位置: 代码迷 >> C语言 >> 这个错误应该怎么修改?
  详细解决方案

这个错误应该怎么修改?

热度:114   发布时间:2007-10-13 16:46:50.0
这个错误应该怎么修改?

#include <stdio.h>
#include <windows.h>

#define N 20

void sjxsb(float,float,float);//此函数用于判断三角形的类型

/*此结构用于存放三角形的三边*/
struct sjx
{
float bian[3];//存放三角形的三条边
};

void main()
{
struct sjx sjx1[N];
int i,num;
printf("\n请输入您要判断的三角形的个数:");
scanf("%d",&num);
for (i=0;i<num;i++)
{
printf("\n请输入三角形的三边,用空格隔开:");
scanf("%f %f %f",&sjx1.bian[0],&sjx1.bian[1],&sjx1.bian[2]);

sjxsb(sjx1.bian[0],sjx1.bian[1],sjx1.bian[2]);

system("pause");
}

}

void sjxsb(float a,float b,float c)//此函数用于判断三角形的类型
{
if(a==b && b==c)
printf("\n该三角形为等边三角形\n\n");
else if(a==b || a==c || b==c)
printf("\n该三角形为等腰三角形\n\n");
else
printf("\n该三角形不是等边三角形\n\n");
}




我用工具检测结果:
--------------------Configuration: cx - Win32 Debug--------------------
Compiling...
cx.cpp
c:\documents and settings\administrator\桌面\cx.cpp(23) : error C2228: left of '.bian' must have class/struct/union type
c:\documents and settings\administrator\桌面\cx.cpp(23) : error C2228: left of '.bian' must have class/struct/union type
c:\documents and settings\administrator\桌面\cx.cpp(23) : error C2228: left of '.bian' must have class/struct/union type
c:\documents and settings\administrator\桌面\cx.cpp(25) : error C2228: left of '.bian' must have class/struct/union type
c:\documents and settings\administrator\桌面\cx.cpp(25) : error C2228: left of '.bian' must have class/struct/union type
c:\documents and settings\administrator\桌面\cx.cpp(25) : error C2228: left of '.bian' must have class/struct/union type
执行 cl.exe 时出错.

cx.obj - 1 error(s), 0 warning(s)

搜索更多相关的解决方案: void  三角形  include  

----------------解决方案--------------------------------------------------------
将三角形结构改为
struct sjx
{
float a;
float b;
float c;
};

----------------解决方案--------------------------------------------------------
错误出现在这里:``你没理解好概念``

看看你定义的: struct sjx sjx1[N];

这个时候再看看``:scanf("%f %f %f",&sjx1.bian[0],&sjx1.bian[1],&sjx1.bian[2]);

重点看 : &sjx1.bian[0],&sjx1.bian[1],&sjx1.bian[2]


看看你哪里马虎了```你没想错```但是失误了```

我刚刚修改了一下```运行成功```

我最近在学结构```还没练习过```这次检查你的错误``就算是练习一下吧``


[此贴子已经被作者于2007-10-13 19:15:34编辑过]


----------------解决方案--------------------------------------------------------
struct sjx sjx1[N]; //一个结构数组

scanf("%f %f %f",&sjx1.bian[0],&sjx1.bian[1],&sjx1.bian[2]); //请问你的sjx1 是什么?只是一个结构变量..

改:
scanf("%f %f %f",&sjx1[0].bian[0],&sjx1[1].bian[1],&sjx1[2].bian[2]);
----------------解决方案--------------------------------------------------------
  相关解决方案