xcode没有显示输出

时间:2014-08-19 07:50:50

标签: c++ xcode

我试了好几次才发现问题出在哪里,但我找不到任何东西。所以,有谁能帮我找到问题,为什么我看不到结果呢?

这似乎是一个愚蠢的问题,但我是编程世界的新手:)

这是我的代码:

#include <iostream>
using namespace std;

// There is the declraction of all functions

float max();
float min();


// This is the main program

int main ( int argc, char ** argv )
{
    // Here you can find max
    max(504.50,70.33);

    // Here you can find min
    min(55.77, 80.12);
    return 0;
}


// This is the max function

int max(float a, float b){

    float theMax;
    if (a>b) {
        theMax = a;
        cout <<theMax ;
    }
    else{
        theMax = b;
        cout << b;
    }
    return theMax;
}

// This is the min function

int min( float c, float d){

    float theMin;
    if (c >d ) {
        theMin =c;
        cout << theMin;
    }
    else {
        theMin =d;
        cout << theMin;
    }
    return theMin;
}

2 个答案:

答案 0 :(得分:1)

您正在呼叫std::maxstd::min。那是因为你写了using namespace std,并且在使用它们之前没有声明你自己的minmax。 (您确实声明了另外两个minmax函数,但这些函数采用零参数,而不是两个参数。因此,当编译器看到max(504.50,70.33);时,唯一的候选者是std::max

答案 1 :(得分:1)

您声明了这些重载:

float max();
float min();

这些函数不带参数并返回float

您正在致电

max(504.50,70.33);

min(55.77, 80.12);

这些函数需要两个double s并且可能会或可能不会返回任何内容 这些匹配std::maxstd::min,而不是您声明的原型。

然后定义

int min( float c, float d){

也与您声明的原型不匹配 换句话说,这些函数在main中是未知的,实际调用的函数是std::minstd::max

请勿使用using namespace std; - 您在输入时节省的内容在清晰度和调试方面都会丢失。

您还应该重命名这些功能 - 重用标准库名称不是一个好主意。