为什么是elapsedtime给我输出1? [英] why is elapsedtime giving me an output of 1?

查看:212
本文介绍了为什么是elapsedtime给我输出1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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;
        }
    }

推荐答案

您有

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

您是不是要

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

更新

由于某种原因,

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

在g ++ 4.7.3下不会产生编译器错误,即使目的是使用 elapsedtime(time1,time2)

does not produce a compiler error under g++ 4.7.3 even though the intent is to use elapsedtime(time1, time2).

我能够成功编译和构建:

I was able to successfully compile and build:

#include <iostream>
using namespace std;

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

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

也许需要另一个SO post来回答这个问题,g ++如何报告错误与上述代码?。

Perhaps another SO post is needed to answer the question, "How does g++ not report error with the above code?".

这篇关于为什么是elapsedtime给我输出1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆