鱼C论坛

 找回密码
 立即注册
查看: 2132|回复: 2

修改代码,使得结果正确

[复制链接]
发表于 2023-12-20 19:16:51 | 显示全部楼层
代码中缺少了头文件的引用,应该加上`#include <iostream>`。

另外,在`display_time()`函数中,缺少了要输出的时间信息。应该在`cout`语句中添加具体的输出内容,例如:
  1. cout << "Time: " << hours << ":" << minutes << ":" << seconds << endl;
复制代码

这样就可以正确显示时间了。

下面是修改后的完整代码:
  1. #include <iostream>
  2. using namespace std;
  3. class Time
  4. {
  5. private:
  6.     int hours, minutes, seconds;
  7. public:
  8.     void get_time()
  9.     {
  10.         cin >> hours >> minutes >> seconds;
  11.     }
  12.     void display_time()
  13.     {
  14.         cout << "Time: " << hours << ":" << minutes << ":" << seconds << endl;
  15.     }
  16. };
  17. int main()
  18. {
  19.     Time t;
  20.     t.get_time();
  21.     t.display_time();
  22.     return 0;
  23. }
复制代码

你可以运行这段代码并输入时间,然后会正确地显示出输入的时间。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-9-22 16:31

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表