0
这是我第一次在这个网站上,正因如此,这个问题的格式在某些方面可能是错误的。这就是说,这是我正在努力的练习。 “编写一个C++程序,提示用户在几秒钟内输入一个事件的运行时间,然后程序以小时,分钟和秒输出运行时间(例如,如果运行时间为9630秒,则输出为二时四十分30秒。)” 以下是我在代码:: Blocks-如何为此添加模数? (小时:分钟:秒)
#include <iostream>
#include <string>
using namespace std;
int main()
{
int seconds;
int hours;
int minutes;
int seconds1;
cout << "How long did the event take in seconds?" << endl;
cin >> seconds;
hours= seconds/3600;
minutes= %(seconds/3600);
seconds1= %(seconds/minutes);
cout << "The event took"<<hours<<":"<<minutes<<":"<<seconds1<<"." << endl;
cout << endl;
return 0;
}
到目前为止编程我的主要问题是如何将我的模运算添加到该程序。我知道我需要包含它,因为在变量之后有一个明确的余数:小时和分钟。
此外,当该程序通过编译运行两个错误代码显示:
Line 16) error: expected primary-expression before '%' token
Line 17) error: expected primary-expression before '%' token
非常感谢您的帮助! –