我试图转换成一个功能的一个非常基本的程序我写道,我也没有结果的研究和修改的代码小时。我的DisplayResults函数调用没有返回值,我不明白为什么。还我想不出如何正确定义"区域"在我的代码,我将提出更容易的方向评论旁边。任何提示或暗示,是极大的赞赏,我只是想了解为什么它不工作
立即诠释的主要()以上是面积被定义的问题...
[编辑:保罗・瓦特改进的代码格式,尖括号]
// TriangleWFunctions.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void pause()
{char junk;
cout << "Press enter to continue...";
cin.ignore();
cin.get(junk);
}
string Readstring ( string prompt )
{
string result;
cout << prompt;
cin >> result;
return (result);
}
int ReadInt ( string prompt )
{
int result;
cout << prompt;
cin >> result;
return (result);
}
int GetLength()
{
int result;
result=ReadInt("Enter the length of the rectangle: ");
return (result);
}
int GetWidth()
{
int result;
result=ReadInt("Enter the width of the rectangle: ");
return (result);
}
int ComputeResult( int length, int width)
{
int result;
result = length * width;
return(result);
}
int DisplayResults(area) //This is where area is saying it's not defined...
{
cout << "\n" << "The area of the rectangle is: " << area;
}
int main()
{
int length, width, area;
length = ReadInt("Enter the Length of the rectangle: ");
width = ReadInt("Enter the Width of the rectangle: ");
// calculate
area = ComputeResult(length, width);
// display results
DisplayResults (area);
// freeze screen to see solution
pause ();
return 0;
}