可以运行但是结果是错的,问题已经解决了,现在提供一下。

这是一个非常简单的矩形的程序,是前期数据结构上的一个例子。但是在VC++下不能正常的运行。

#include "stdafx.h"
#include "iostream.h"

struct Rectangle
{
      float length,width;
};
void InitRectangle(Rectangle r,float length,float width);
float Circumference(Rectangle r);
float Area(Rectangle r);

void InitRectangle(Rectangle r,float len,float wid)
{
r.length=len;
r.width=wid;
}
float Circumference(Rectangle r)
{
return 2*(r.length+r.width);
}

float Area(Rectangle r)
{
return r.length*r.width;
}


void main(void)
{
float x,y;
float p,s;
Rectangle a;
cout < <"请输入一个矩形的长和宽!" < <endl;
cin>>x>>y;
InitRectangle(a,x,y);
p=Circumference(a);
s=Area(a);
cout < <endl;
cout < <"矩形的周长为" < <p < <endl;
cout < <"矩形的面积为" < <s < <endl;
}

 

解决方法是

 

#include "stdafx.h"
#include "iostream.h"

typedef struct
{
float length,width;
}Rectangle_struct;

void InitRectangle(Rectangle_struct& r,float length,float width);
float Circumference(Rectangle_struct& r);
float Area(Rectangle_struct& r);

void InitRectangle(Rectangle_struct& r,float len,float wid)
{
 r.length=len;
 r.width=wid;
}
float Circumference(Rectangle_struct& r)
{
 return 2*(r.length+r.width);
}

float Area(Rectangle_struct& r)
{
 return r.length*r.width;
}


void main(void)
{
 float x,y;
 float p,s;
 Rectangle_struct a;
 cout <<"请输入一个矩形的长和宽!"<<endl;
 cin>>x>>y;
 InitRectangle(a,x,y);
 p=Circumference(a);
 s=Area(a);
 cout<<endl;
 cout<<"矩形的周长为"<<p<<endl;
 cout<<"矩形的面积为"<<s<<endl;
}

 

问题出在VC++的MFC上。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值