0

How do you write a program, which compares correctly two real numbers with accuracy at least 0.000001?

16th Apr 2017, 3:21 PM
Mandla Phillip Ndimande
Mandla Phillip Ndimande  - avatar
11 Respostas
+ 23
@Mandla this takes absolut values of a and b and does the following (if (a-b) <0.000001 (ideally that must be: a-b = 0) then a == b) but if a < b it'll say false anyway https://code.sololearn.com/cddiqf9EtJPJ/?ref=app
16th Apr 2017, 11:29 PM
Illusive Man
Illusive Man - avatar
+ 22
😆
17th Apr 2017, 12:11 AM
Illusive Man
Illusive Man - avatar
+ 22
here it`s 3.30am.. well, then we`ll need smthn to not miss those questions
17th Apr 2017, 12:32 AM
Illusive Man
Illusive Man - avatar
+ 21
@Mandla Convert.ToDouble(Console.ReadLine(()); idk but u can write smth like this "Evaluated with accuracy of 0.000001 ))"
16th Apr 2017, 11:56 PM
Illusive Man
Illusive Man - avatar
+ 19
@Mandla post here example of your current code plz
16th Apr 2017, 10:53 PM
Illusive Man
Illusive Man - avatar
+ 5
How about multiplying them by 1000000?
16th Apr 2017, 3:34 PM
Dinmukhamed Mailibay
Dinmukhamed Mailibay - avatar
+ 2
@Illusive man You have officially become my go to bro cause my brains are burning, I'm complete newbie at this. Thanks a million Illusive man
17th Apr 2017, 12:07 AM
Mandla Phillip Ndimande
Mandla Phillip Ndimande  - avatar
+ 1
illusive man I'm studying c# fundamentals this was question 3 of the exercise. I was asked to compare correctly two real numbers with accuracy of at least 0.00001.
16th Apr 2017, 11:07 PM
Mandla Phillip Ndimande
Mandla Phillip Ndimande  - avatar
+ 1
@Illusive man Where do you get the values you gave to the variables you initiate and how does one find or know the accuracy of 0.000001? By the way thanks for your help Exercise 5 is the worst I'm asked to declare a variable of type char, assign it as a value the character, which has a Unicode code 72 and display it as a hexadecimal representation.
16th Apr 2017, 11:49 PM
Mandla Phillip Ndimande
Mandla Phillip Ndimande  - avatar
+ 1
Bro I'm in South Africa and it's past 2 am I 'm waking up in 5 hrs to go to campus I will be posting more Questions and I wish to hear from you again. 😮😮
17th Apr 2017, 12:26 AM
Mandla Phillip Ndimande
Mandla Phillip Ndimande  - avatar
0
The guideline gave me an e.g. bool equal = Math.Abs(a-b) < 0.000001; But I still don't understand how this work🙁
16th Apr 2017, 3:40 PM
Mandla Phillip Ndimande
Mandla Phillip Ndimande  - avatar