why dose "i" have three numbers when it output ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

why dose "i" have three numbers when it output ?

when I input a number liks 0.00000056 it output 5.6e-007 I can't understand why not 5.6e-7 https://code.sololearn.com/cP0j9X70Ak20/?ref=app

13th Oct 2018, 5:55 PM
Yui Yuuki
Yui Yuuki - avatar
2 Answers
+ 1
Yui Yuuki I revisited your Code. The Bug is that the first Condition is always true. You can see it, when you change the Line 'cout<<num;' and delete the Line 'cout<<num<<"e"<<i<<endl;'
14th Oct 2018, 7:02 PM
Sebastian Keßler
Sebastian Keßler - avatar
+ 1
The Scientific Notation Assignment is a hard Nut for a Beginnner. Some Hints for your Code: Why do you define num as a Float and not as an Integer? Your first if-Statement is very complex and redundant num==0||1<=num<=10||-10<=num<=-1 is the same as num >=-10 && num <= 10 The Block after this if-Statement will be executed when num is between -10 and 10. So the test in the following else-Block is not necessary: else{ if(num>=10||num<=-10) If the previus if-Statement is false, this Condition is always true.
13th Oct 2018, 8:30 PM
Sebastian Keßler
Sebastian Keßler - avatar