-1
#include <iostream>; 

using namespace std; 

int main() 

{ 

    int  total_of_seconds; 

cout << "please inter the total of seconds \n"; 

cin >> total_of_seconds ;

int seconds_per_day = 24* 60 *60 ;

int seconds_per_hours = 60 * 60 ;

int seconds_per_minutes= 60 ;

int number_of_days = floor (total_of_seconds/seconds_per_day) ;

int s = total_of_seconds % seconds_per_day ;

int number_of_hours=  floor (s/seconds_per_hours ) ;

int s %= seconds_per_hours;

int number_of_minutes= floor (s/seconds_per_minutes) ;

int s %= seconds_per_minutes;

int number_of_seconds = s;

cout << number_of_days <<":" << number_of_hours <<":" << number_of_minutes<< ":" << number_of_seconds<<endl ;

return 0;

}
/tmp/uGTkaIpa1f.cpp:11:22: error: 'floor' was not declared in this scope
   11 | int number_of_days = floor (total_of_seconds/seconds_per_day) ;
      |                      ^~~~~
/tmp/uGTkaIpa1f.cpp:14:7: error: expected initializer before '%=' token
   14 | int s %= seconds_per_hours;
      |       ^~
kiner_shah
  • 3,939
  • 7
  • 23
  • 37

1 Answers1

1

You have declared your variable at

int s = total_of_seconds % seconds_per_day ;

and you're trying to re-declare it at

int s %= seconds_per_hours;

remove the int declaration

P.S. include the cmath for using floor

Abdel
  • 404
  • 2
  • 8
  • Thanks it works know, i didn't know those information. – Mahammad Qasm Sep 27 '22 at 13:49
  • But using `std::floor()` is pointless since only integer division is involved. – Fareanor Sep 27 '22 at 14:21
  • Well, what if the division is 10/3 for example ? yes they both are integers, but the result is a float (~3.33), when assigning this value to an integer type variable, you would have got a warning that you can't implicitly (automatically) convert a `float` to an `int`, as you lose the decimal. Well, he could use `(int)` or `static_cast` but that's up to him. – Abdel Sep 27 '22 at 14:29
  • @Abdel: In C++, 10/3 is **exactly** 3. Not 3.0 or 3.3, but 3 without a fractional part. `float` can have fractional parts (if small enough); we avoid the word "decimal" there because the fractional part is also binary. (1/2, 1/4, 1/8 etc) – MSalters Sep 27 '22 at 15:34