【发布时间】:2013-12-27 05:27:33
【问题描述】:
我正在编写一个计算三角形斜边的程序,但不知何故,我遇到了一些意想不到的错误,或者更像是运行时错误,可悲的是,我什至不知道自己的错误.无论如何,这是我的代码,我会很高兴得到答案
#include <iostream>
using namespace std;
//function prototype
double hypotenuse(double leg1, double leg2);
double leg(double hypotenuse, double leg);
void main()
{
//local variable
double leg1;
double leg2;
//user interface
cout << "Enter the first leg of the triangle: ";
cin >> leg1;
cout << "Enter the second leg of the triangle: ";
cin >> leg2;
cout << "The value of hypothesis is: " << hypotenuse(leg1,leg2) << endl;
system("pause");
}
double hypothenuse(double leg1, double leg2)
{
return ((leg1 * leg1) + (leg2 * leg2));
}
【问题讨论】:
-
您到底遇到了什么错误?
-
那么,你的问题是它计算了错误的值,还是别的什么?
-
你确实忘记在小边函数中取平方根。
-
不是这样,每次我运行这个程序都会给我错误,不是这样,它甚至不会突出我的错误
-
请编辑您的帖子并包含有关错误的详细信息。它是否返回错误的值?它会崩溃吗?它是用咖啡代替茶吗?
标签: c++ visual-studio-2010 visual-c++ runtime-error