将一个值递增一定次数

Incrementing a value a certain amount of times

本文关键字:一个      更新时间:2023-10-16

用户在手机和电脑上输入两次。如果它们不同,我需要让它们相等。然后我需要将电脑的时间增加到比手机时钟快1小时5分23秒。

这是我的if语句。

   if (!myComputerClock.equalTime(cellPhoneClock))
    {
        myComputerClock=cellPhoneClock; 
        cout << "  The new time is: n";
        cout << "  Cellphone: ";
        cellPhoneClock.printTime();
        cout << endl << endl;
        cout << "  Computer: ";
        myComputerClock.printTime();
    }
    else 
    {
        myComputerClock.incrementHours();
        myComputerClock.incrementMinutes();
        myComputerClock.incrementSeconds();
    }

您需要决定要同步到哪个时钟,然后为每个setTime调用编写两行代码。setTime既不是左值也不是右值(这意味着它既不接受也不返回值),这就是错误告诉您的。