K
K
Kircha2018-09-13 22:43:23
C++ / C#
Kircha, 2018-09-13 22:43:23

Can you help with the scarf?

double b;
            const double PI = 3.14159265;
            double result2;

            Console.WriteLine("1/4 - 1/4(sin(5/2*PI - 8b)) = ...");
            Console.WriteLine("Введите b");
            b = Convert.ToDouble(Console.ReadLine());

            result2 = 1 / 4 - (1 / 4 * Math.Sin((5 / 2 * PI) - (8 * b)));
            result2 = Math.Round(result2, 3);

            Console.WriteLine("1/4 - 1/4(sin(5/2*PI - 8b)) = " + result2);

does not display result2 correctly. I would be very grateful if you point out the error

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrew K., 2018-09-13
@Kircha

1 / 4 == 0, because 1 and 4 are integer constants, and when dividing integers, real ones cannot be obtained. If you want a double type, then write 1D / 4D

#
#, 2018-09-14
@mindtester

or like this

result2 = 1.0 / 4.0 - (1.0 / 4.0 * Math.Sin((5.0 / 2.0 * PI) - (8.0 * b)));

S
sokolov_andrei2013, 2018-09-14
@sokolov_andrei2013

First, why do you need a PI variable? There is Math.PI with type double. Farther. Why do you need an extra calculation like 1/4 if you can write 0.25 and replace 5/2 with 2.5?
Further, the output to the screen is not particularly correct. Can be replaced with:
Console.WriteLine( "0.25 - 0.25(sin(2.5*PI - 8b)) ={0} ", result2).
This would be the correct conclusion. Further, it is still necessary to clarify whether this is the whole program or some method. If a method, then typing to the screen in the method is an OOP error.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question