帮我解决这个问题.我所有的答案都是零.你能告诉我我的错误是什么吗? [英] help me fix this. all my answers are zero. can you tell me whats my error here?

查看:107
本文介绍了帮我解决这个问题.我所有的答案都是零.你能告诉我我的错误是什么吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<stdio.h>

int l,wd,r,s;
double pi=3.14;
double Rectangle()
{
 double rec;
 rec=l*wd;
 return(rec);
}
double Square()
{
 double squ;
 squ=s*s;
 return(squ);
}
double Circle()
{
 double cir;
 cir=pi*(r*r);
 return(cir);
}
void entry()
{
 printf("Enter length\t: ");
 scanf("%d",&l);
 printf("Enter width\t: ");
 scanf("%d",&wd);
 printf("Enter radius\t: ");
 scanf("%d",&r);
 printf("Enter side\t: ");
 scanf("%d",&s);
}
main()
{
 double area;
 clrscr();
 entry();
 printf("\n");
 area=Rectangle();
 printf("The area of Rectangle is : %g\n",area);
 area=Square();
 printf("The area of Square is\t : %g\n",area);
 area=Circle();
 printf("The area of Circle is\t : %g\n",area);
 getch();
}

推荐答案

当我使用以下输入尝试您的程序时:
When I try your program with the following input:
Enter length    : 10
Enter width     : 12
Enter radius    : 4
Enter side      : 6



输出如下:



The output is as follows:

The area of Rectangle is : 120
The area of Square is    : 36
The area of Circle is    : 50.24



这似乎是正确的.
观察;您的计算函数(矩形,正方形,圆形)返回双精度数,您是否尝试输入双精度数作为输入?当我输入12.0作为第一个输入时,将不再接受其他输入,并且所有输入均为0.

对于现有程序,请确保输入整数作为输入.如果这还不够,请将输入变量(l,wd,r,s)转换为两倍,并相应地调整scanf.



This seems to be correct.
Observation; your calculation functions (Rectangle, Square, Circle) return doubles, did you perhaps try to enter doubles as input? When I enter 12.0 as first input, no further input will be accepted and everything will be 0.

For the existing program, make sure you enter integers as input. If this is not sufficient, convert your input variables (l, wd, r, s) to double and adjust your scanf accordingly.


将值分配给l,wd的位置,r和s?

看起来好像它们为null,因此结果将为0


糟糕,没看到!

看起来您正在将公式应用于Rectangle(),但没有将值应用于变量.

这是spme伪代码:
Where are you assigning values to l,wd,r and s?

It looks as though they are null, therefore result will be 0


Oops, didn''t see it!

It looks like you are applying the formula to Rectangle() but without the values applied to the variables.

Here is spme pseudo code:
int l,wd,r,s
input l
input wd
input r
input s

double rec=l*wd
double sqr=s^2
double circ=pi*r^2

output rec
output sqr
output circ



适应您的需求.



adapt to your needs.


这篇关于帮我解决这个问题.我所有的答案都是零.你能告诉我我的错误是什么吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆