2010-11-27 26 views
0

に、私は数週間のために、このC++ソースファイルに取り組んできたと私が間違っているつもりかを理解していない...空の戻り値の型C++

//This program will ask the user for the measurement of all 3 sides of a triangle 
//and first determine if the numbers will equal a triangle, then give the area and 
//perimeter of the triangle. 

#include <iostream> 
#include <cmath> 
#include <iomanip> 
using namespace std; 

void calc(double , double , double ,double &, double &); 
void s(double , double , double , double &); 

int main() 
{  
    double a; 
    double b; 
    double c; 
    double per; 
    double sr; 
    double areat; 

    cout<<"Enter the three side of your triangle: "; 
    cin>> a >> b >> c; 
    per = a+b+c; 

    if (a > b || a < b || b > c || b < c) 
    { 
     cout<< "Sorry, this is not a triangle.\n"; 
    } 
    else 
    { 
     cout<<"For a Triangle with the sides of "<<a<<", "<<b<<",and " <<c <<endl; 
     cout<< setprecision(3)<<fixed<<showpoint; 
     cout<<"The Perimeter is "<<per<<endl; 
     calc(a,b,c,sr,areat); 
     cout<< "The Area is "<<areat<<endl; 
    } 
    system ("pause"); 
    return 0; 
}  

void s(double a, double b, double c, double &sr) 
{ 
    sr = (a+b+c)/2; 
} 

void calc(double a, double b, double c, double &sr, double &areat) 
{ 
    areat = sqrt(sr*(sr-a)*(sr-b)*(sr-c)); 
} 
+0

コードを再フォーマットし、問題がどこにあるのかをお知らせください – kellogs

+0

問題はなんですか? 「うまくいかない」と言うだけではなく、私たちがあなたを助けるためにいくつかの詳細を教えてください。 – suszterpatt

+0

読みやすいように編集されました。 –

答えて

5

変数srが初期化されていません。

その他のマイナーなもの:

if (a > b || a < b || b > c || b < c) 
    cout << "Sorry, this is not a triangle.\n"; 

この行は== bは== Cのない限り、全ての三角形を拒否します。正三角形に制限するつもりでしたか?

calc()の場合、srは出力ではないため、参照渡しする必要はありません。

+0

Aaaahhhあなたは私が入力できるより速くそこに着いた。 +1。 –

+0

私は何かが見つからない限り、 'calc'と同じことが起こります。 – Maxpm

+4

@NineFingers明らかに、より多くの指が必要です。 Zecc