0

can anyone help me with this assignment, Please.

The brightness of a binary star varies as follows. At time t = 0 days its magnitude is 2.5, and it stays at this level until t = 0.9 days. Its magnitude is then determined by the formula

3.355-ln(1.352+cos(PI(t-0.9)/0.7))

Until t = 2.3 days its magnitude is then 2.5 until t = 4.4 days, and it is then determined by the formula

3.598-ln(1.998+cos(PI(t-4.4)/0.4))

Until t = 5.2. It then remains at 2.5 until t = 6.4 days, after which the cycle repeats with a period of 6.4 days.

Write a program which will input the value of t and print the brightness of the star at that time. Use the value of PI = 3.14285714.

Your program should give the user the option to repeat the process of computing the brightness of star or stop (EXIT) the code. Also, you should use nested if , switch control structure statements in your solution. Your results should be displayed in five decimal places.

My main problem is what will be the condition for the loop ?

and is it better to use while() or do{} while() ?

4
Contributors
5
Replies
27
Views
8 Months
Discussion Span
Last Post by Gamal_3
1

The cycle repeats with a period of 6,4 days. That should give you a hint for the for loop.

0

Giving it another thought, I finally figured it out.

Thanks @ddanbe .

3

Use the value of PI = 3.14285714

To 8 decimal places, the value of PI is 3.14159265. What is the point of using 8 decimal places when your third place is already wrong?

and is it better to use while() or do{} while() ?

It doesn't matter unless your equations are correct.

Edited by Reverend Jim

Votes + Comments
Explainer. 22/7 thinking. Try 355/113 or the real Pi.
Eagle eye!
2

is it better to use while() or do{} while?

That depends on what behaviour you want!
while tests the condition before entering the loop. The loop is executed zero or more times
do whiletests the condition after each pass of the loop. The loop is executed at least once.

In any given situation it will usually be obvious which is the more appropriate

Votes + Comments
Well explained.
0

To 8 decimal places, the value of PI is 3.14159265. What is the point of using 8 decimal places when your third place is already wrong?

It doesn't matter unless your equations are correct.

About the value of PI, I noticed it earlier and went to ask the instructor about it. His answer was simply to program it as we were given .. It's an nnoying thing, you never know what is their purpose of doing such things sometimes.
Anyway, Thanks for noticing and your help :)

while tests the condition before entering the loop. The loop is executed zero or more times
do whiletests the condition after each pass of the loop. The loop is executed at least once.
In any given situation it will usually be obvious which is the more appropriate

That's something to be always keept in mind. Thanks a lot for your help :D

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.