+ 1
[C++] How to make decimal within loop?
How do you make whole number a decimal with a loop?
6 ответов
0
First, what is the whole number for? is it the loop counter or something else?
Maybe it's even better if you can share your code bits' link, sometimes codes represents itself better than words.
https://www.sololearn.com/post/75089/?ref=app
0
https://code.sololearn.com/cz4697qsXKoS/?ref=app
0
How do I make the output count minutes with a decimal?
0
Are you trying to display the time or just the value of <num>? things will be different cause time has 3 parts (hour, minute & second). But a floating point value only has 2 (integral & fractional part).
Additionally, floating point value suffers from precision issue, and it's why we are recommended to use whole number as loop counter.
And looking at the code, there are a few problems
int num = 1.01; // initialization of integer by floating point literal
while (num < 24.01) // comparison of integer to floating point literal
num = num + 1.01; // addition of floating point literal to an integer
If your intention was to display the time, I think you'd need another approach.
0
I just want to know how to make the number a floating point without writing 50+ lines
0
There are two ways I'm aware of
* C way of type casting
int number = (int)12.345; // <number> will be 12
* C++ way of type casting
https://en.cppreference.com/w/cpp/language/explicit_cast