Same as minutes. (60*60*f)%60. There are 60*60 seconds in an hour and the cycle is 60 secs.
Though if f is float, so is 60*60*f and you can't do % with floats. You'll have to cast it to an int.
Srry about question i should make it more clear
and tnx to all of you it worked i dont know how i didnt think reversing 1st method of mine it was Second/3600 ofc it is 60*60.Oh my my sometimes my brain stops
"hamsterman (1614) Link to this post Feb 15, 2011 at 11:25pm
Same as minutes. (60*60*f)%60. There are 60*60 seconds in an hour and the cycle is 60 secs.
Though if f is float, so is 60*60*f and you can't do % with floats. You'll have to cast it to an int."
didnt get it why i cant use moduler divide on floats and what do u mean by casting int(make it as paramater ? )
int main(){
float f = 7.5;
float g = f*2 % 5;
return 0;
}
I get "error C2296: '%' : illegal, left operand has type 'float' ". Don't you?
You then have to change float to int. That would be either g = int(f)*2%5; or g = int(f*2) % 5;. Conversion to int rounds down, so in the first version g = 7*2%5 = 4 and in the second one (7.5*2)%5 = 15%5 = 0 which is the correct answer.
let me show you full of mine program and the questions of Prof.I still dont believe im doin right :/(didnt compile it yet)
Create a class to operate on time and time intervals.Call the new class Time. All the three
Data components in this class for hours, minutes, seconds are integer variables. Minutes and seconds may contain values in the range 0…59. Include member functions and constructors to initialize Time to 0 and to initialize it to fixed values. A getdata() method should read validate data from standart input. A member function should display it 24 hour cycle format from 0:0:0 to 23:59:59. Include member function that permit data conversion in both directions :
• From real (float) value (1.5f hours ) to hours/min/sec (1h,30min,0sec)
• From hour/min/sec (1h,30min,0sec) to real (float) value (1.5f hours)
class Time
{
Public: // reserved word is lowercase
int Hours;
int Minutes;
int Seconds;
} // missing semicolon
void Time() // Error here (part of class, Time is constructor, no type)
{
Hours=0;
Minute=0;
Seconds=0;
}
void Time(int h,int m,int s) // Error here (part of class, Time is constructor, no type)
{
Hours=h;
Minute=m;
Seconds=s;
}
void getdata(int h,int m,int s) // Error here (part of class?)
{
if(h>=0&&h<24); // Error here (semicolon?)
Hours<<h // Error here (semicolon? Assignment)
if(m>=0&&m<60); // Error here (semicolon?)
Minutes<<m // Error here (semicolon? Assignment)
if(s>=0&&s<60); // Error here (semicolon?)
Seconds<<s // Error here (semicolon? Assignment)
}
Void timer(float f) // lowercase reserved word void, part of class?
Hours=f;
Minutes=(60*f)%60;
Seconds=(60*60*f)%60;
}
Float Reverse(in h,int m,int s) // lowercase reserved word float, part of class?
{
float=h+(m/60)+(s/3600);
}
f-=Hours=f;//subtracts integer component of f from f, simultaneously assigning it to Hours.
Minutes=f*=60;// multiplied f by 60 and puts the integer part in Minutes
f-=Minutes;
Seconds=f*60;
how about "A member function should display it 24 hour cycle format from 0:0:0 to 23:59:59"
i got an idea but still dunno how to code it(it will be in ma main?)