+ 1

HOW CAN I MAKE IT WHEN I INPUT 11.6 the output is 11 hours 60 minutes and 0 degrees

#include <iostream> using namespace std; int main () { int a, b, c; double x; cout << "Input time: "; cin >> x; a = x; b = ((x-a)*100); c = (a*30 + (b/2)) % 360; cout << a << " hours " << b << " minutes and " << c << " degrees."; return 0; }

20th Sep 2024, 9:09 AM
Lewis He
Lewis He - avatar
5 odpowiedzi
+ 5
Byabasajja Matayo & Elle please keep comments relevant to the discussion. If you have a new question then put your question in a new Q&A post.
21st Sep 2024, 2:20 PM
Brian
Brian - avatar
+ 3
What are you converting to? if it is time, 11.6 is not 11h 60m 0s. 60m would carry over to +1h. minutes at most only goes to 59. Same with seconds. 11.6 would only be 11h 35m 59s. And why is there degrees? Are you sure about the calculation for c? Here is a quick decimal time converter. https://sololearn.com/compiler-playground/cl3y0C53bPR1/?ref=app
20th Sep 2024, 12:24 PM
Bob_Li
Bob_Li - avatar
+ 2
Lewis He ok, you can force the answer you want. But I am still unclear about your calculation for c, or how this is of any practical use... //HOW CAN I MAKE IT WHEN I INPUT 11.6 the output is 11 hours 60 minutes and 0 degrees #include <iostream> #include <cmath> using namespace std; int main () { int a, c; double b, x=11.6; //uncomment for user input //cout << "Input time: "; //cin >> x; a = x; b = ((x-a)*100); c = (a*30 + (int)ceil(b)/2) % 360; cout << a << " hours " << b << " minutes and " << c << " degrees."; return 0; }
21st Sep 2024, 1:53 AM
Bob_Li
Bob_Li - avatar
+ 1
How to put animate in web page
21st Sep 2024, 1:42 PM
Byabasajja Matayo
Byabasajja Matayo - avatar
0
How to create a Vourse certificate from sololearn?
21st Sep 2024, 3:23 PM
Elle
Elle - avatar