2016-10-02 13 views
0

こんにちは私は学校のプロジェクトに取り組んでおり、このコードをすべてゼロから作成しています。私は、2つ以外のすべてのエラーを解決したので、ちょっと混乱しています。誰かが私のソースコードを見て、私が間違っていることと解決方法を教えてくれるのだろうかと思っていました。ありがとう!ここで戻り値の型だけで区別される関数をオーバーロードできないC++

はエラー

IntelliSenseのです: "ダブル"

の存在に "のstd ::文字列" からノー適した変換関数:戻り値の型だけで

のIntelliSenseで区別機能をオーバーロードすることはできません

そして私のソースコード。

#include <iostream> 
#include <string> 
using namespace std; 

//Global Constants 
const double BMI_FACTOR = 703; 
const double MASS_LOWER_LIMIT = 18.5; 
const double MASS_UPPER_LIMIT = 25.0; 

//Function Prototypes 
double getWeight(); 
double getHeight(); 
double setMass(double, double); 
string setOverUnder(double); 
void showBMI(string, double); 

//Begin Main 
int main() { 

    //Variable Declaration 
    double weight; 
    double height; 
    double BMI; //Body Mass Index 
    string healthStatus; //Either Optimal, Under, or Over-weight 

    //Get the user's weight 
    weight = getWeight(); 

    //Get the user's height 
    height = getHeight(); 

    //Calculate the user's BMI 
    BMI = setMass(weight, height); 

    //Determine the user's health status based on BMI 
    healthStatus = setOverUnder(BMI); 

    //Displays the user's BMI and health status 
    showBMI(healthStatus, BMI); 

    return 0; 

//End Main 
} 

//Function getWeight 
double getWeight() { 

    //Local Variable Declaration 
    double totalWeight; 

    //User Input for Weight 
    cout << "Enter weight in pounds." << endl; 
    cin >> totalWeight; 

    //Return the value for totalWeight to caller 
    return totalWeight; 

//End Function getWeight 
} 

//Function getHeight 
double getHeight() { 

    //Local Variable Declaration 
    double totalHeight; 

    //User Input for Height 
    cout << "Enter height in inches." << endl; 
    cin >> totalHeight; 

    //Return the value for totalHeight to caller 
    return totalHeight; 

//End Function getHeight 
} 

//Function setMass 
double setMass(double localVarWeight, double localVarHeight) { 

    //Local Variable Declaration 
    double totalMass; 

    //Calculate the user's BMI 
    totalMass = (localVarWeight * BMI_FACTOR)/(localVarHeight * localVarHeight); 

    //Return the value of totalMass to the caller 
    return totalMass; 

//End Function setMass 
} 

//Function setOverUnder 
double setOverUnder(double localVarMass) { 

    //Local Variable Declaration 
    string wellBeing; 

    //Determine user's health 
    if (localVarMass < MASS_LOWER_LIMIT) 
     wellBeing = string("underweight."); 
    else if (localVarMass > MASS_UPPER_LIMIT) 
     wellBeing = string("overweight."); 
    else 
     wellBeing = string("optimal weight."); 

    //Return the value of wellBeing to the caller 
    return wellBeing; 

//End Function setOverUnder 
} 

//Function showBMI 
void showBMI(string localVarHealth, double localVarMass) { 

    //Display user's BMI 
    cout << "Your BMI is " << localVarMass << endl; 

    //Display user's health status 
    cout << "You are " << localVarHealth << endl; 

//End Function showBMI 
} 
+0

ここにダンプしたコードのどの行がこのエラーを生成しているのですか?おそらく、より具体的に問題を説明すると、人々があなたを手助けするのがより簡単になるでしょう。 –

答えて

1

関数宣言でstringを戻り値の型として宣言しましたが、定義にstringの代わりにdoubleを使用しました。だからこそコンパイルしていないのです。

+0

ありがとう!それが問題でした、どのようにばかげた。 – 0N3KN0WN

1

エラーを解決するには、文字列を返すようにsetOverUnder定義を変更する必要があります。

IntelliSenseは:

setOverUnder関数宣言(返す文字列)がその定義と一致していないので(ダブル返します)だけで戻り値の型で区別機能をオーバーロードすることはできません。

のIntelliSense:あなたは、二重返す関数setOverUnderから文字列(ウェルビーイング)を返すようにトリングされているので

存在する「ダブル」を「STD ::文字列」からノー適した変換関数。

関連する問題