+ 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; }
7 Réponses
+ 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.
+ 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
+ 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;
}
+ 2
Brian Can't Keep Comments and Can't Relevant to the discussion 😁.
+ 1
How to put animate in web page
0
No Problem. I'll help you code . Check my code :
https://www.sololearn.com/en/compiler-playground/cvXzFabR1s6X
0
How to create a Vourse certificate from sololearn?