kaleidoscopes | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

kaleidoscopes

Help why getting int value Not decimal #include <iostream> using namespace std; int main() { int kaleidoscopes; cin>>kaleidoscopes; float i,b; int j= kaleidoscopes*5; if(kaleidoscopes>=1){ b=(10/100)*j; i = (7/100)*b; } float d=(j-b)+i; cout<<d; }

10th Nov 2022, 6:08 AM
herik Sevak
1 Answer
+ 6
10 / 100 = 0 7 / 100 = 0 If you divide two integers, the result is truncated to an int. Solution 1: use at least one float operand then the other one is implicitly converted to float. 10.0 / 100 Solution 2: use float variables, and in your compound formula make sure you start the operation with one float type at least float_var * 10 / 100
10th Nov 2022, 6:23 AM
Tibor Santa
Tibor Santa - avatar