-1

In this code I have defined the remainder in this code as float data type but the compiler rejected that and suppose to defien it as an inegral type what is the reasone for this issue? enter image description here

int main()
{

    float days, hours, minutes, seconds;
    float Totalseconds;
    float Remainder;
    float secondsperday;
    float secondsperhour;
    float secondsperminute;

    secondsperday = 24 * 60 * 60;
    secondsperhour = 60 * 60;
    secondsperminute = 60;


    cout << "Enter total seconds\n";
    cin >> Totalseconds;

    days = floor(Totalseconds / secondsperday);
    Remainder = (Totalseconds % secondsperday);

    hours = floor(Remainder / secondsperhour);
    Remainder = Remainder % secondsperhour;

    minutes = floor(Remainder / secondsperminute);
    Remainder = Remainder % secondsperminute;

    seconds = Remainder;

    cout << days << ":" << hours << ":" << minutes << ":" << seconds;


    return 0;
}
Obsidian
  • 3,719
  • 8
  • 17
  • 30
  • Welcome to Stack Overflow! Please, [don't post your code/error messages as images](https://meta.stackoverflow.com/a/285557/4298200). Firstly we want to copy/paste it and secondly search engines are unable to index that information. So please make sure that any textual information is actually provided in text form. – 273K Jun 26 '23 at 00:16
  • *expression must have **integral** or unscoped enum type on %* - what don't you understand there? Are `Totalseconds ` and `secondsperday` and other integral types? – 273K Jun 26 '23 at 00:17

1 Answers1

1

expression must have integral or unscoped enum type on %

Floating-point numbers like float don't have a % operator in C++. They are neither integral (i.e. integers like int) nor unscoped enumerations (i.e. enum), so you're getting this error.

If you wanted a floating-point remainder that works similarly to % operator, you could use std::fmod:

Remainder = std::fmod(Totalseconds, secondsperday);

However, in your code, it looks like none of the numbers have to be float (unless Totalseconds can be 123.456 for example). If you simply changed all of the float types to int, this code would also compile.

Jan Schultke
  • 17,446
  • 6
  • 47
  • 96