我已完成該程序,但出現一個錯誤。它表示總和,分鐘,小時,秒在此函數中未初始化。我試過使用不同的變量,並初始化變量,但它仍然無法工作。有人能幫我弄清楚我做錯了什麼。我把time(total,hours, mins, secs);
變量在此函數中未初始化使用
#include <iostream>
using namespace std;
void time(int, int, int, int);
int main()
{
int total;
int hours;
int mins;
int seconds;
int secs;
cout << "Enter the number of seconds: ";
cin >> seconds;
time(total, hours, mins, secs);
cout << "The number of hours is: " << hours << endl;
cout << "The number of minutes is: " << mins << endl;
cout << "The number of seconds is: " << secs << endl;
return 0;
}
void time(int total, int &hours, int &min, int &sec)
{
int rem1;
hours = total/3600;
rem1 = total % 3600;
min = rem1/60;
sec = rem1 % 60;
return ;
}
編譯器輸出:
15:38: warning: 'total' is used uninitialized in this function [-Wuninitialized]
15:38: warning: 'hours' is used uninitialized in this function [-Wuninitialized]
15:38: warning: 'mins' is used uninitialized in this function [-Wuninitialized]
15:38: warning: 'secs' is used uninitialized in this function [-Wuninitialized]
我已經完成了程序,但我發現了一個錯誤。它表示總和,分鐘,小時,秒在此函數中未初始化。我試過使用不同的變量,並初始化變量,但它仍然無法工作。有人能幫我弄清楚我做錯了什麼。我把時間(總計,小時,分鐘,秒);
您的函數'time'聲明與函數'time'的定義不匹配。這意味着它們是兩種不同的功能,你應該得到一個「未解決的符號」錯誤。 – aschepler
''total''參數中'time()'應該用'seconds'調用? – corn3lius