为什么elapsedtime给我输出1?

时间:2014-05-07 22:25:47

标签: c++ function time

int elapsedtime(int time1, int time2)
{
int minutes1 = ((time1/100*60)+(time1%100);
int minutes2 = ((time2/100*60)+(time2%100);
return(minutes2-minutes1);
}

/ ************* *************

do
    {
        cout << "What is your starting time? ";
        cin >> time1;
        cout << "What is your ending time? ";
        cin >> time2;

        if (time2>=time1)
        {
        cout << "Your elapsed time is " << elapsedtime <<endl;
        cout << "If you would like to enter other times?(Y/N)" <<endl;
        cin >> choice;
        }
        else
        {
        cout << "Error: Your starting time must be lower than your ending time."<<endl;
        cout << "If you would like to enter other times?(Y/N)" <<endl;
        cin >> choice;
        }
    }

每经过一段时间我都会得到1的输出?

1 个答案:

答案 0 :(得分:4)

你有

    cout << "Your elapsed time is " << elapsedtime <<endl;

你的意思是

    cout << "Your elapsed time is " << elapsedtime(time1, time2) <<endl;

<强>更新

出于某种原因,

    cout << "Your elapsed time is " << elapsedtime <<endl;
即使意图使用elapsedtime(time1, time2)

也不会在g ++ 4.7.3下产生编译器错误。

我能够成功编译和构建:

#include <iostream>
using namespace std;

int elapsedtime(int time1, int time2)
{
   return 0;
}

int main()
{
   cout << "Your elapsed time is " << elapsedtime <<endl;
}

也许需要另一篇SO帖子来回答这个问题,&#34; g ++如何报告上述代码的错误?&#34;。