{"id":12341,"date":"2021-12-09T02:30:50","date_gmt":"2021-12-09T02:30:50","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=12341"},"modified":"2021-12-09T02:31:16","modified_gmt":"2021-12-09T02:31:16","slug":"program-to-calculate-force-btw-2-objects","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/programming\/program-to-calculate-force-btw-2-objects\/24413.html","title":{"rendered":"Program To Calculate Force Btw 2 Objects"},"content":{"rendered":"<p>I am also new to C++. This is my first class, second program. I&#8217;m a math major and this is a requirement. This assignment was to write a program that calculates the force between 2 objects. My program is to prompt the user for m1, m2, initial distance apart, end distance apart t. I need to utilize the Read Double function since we just went over that in the prior class. Additionally, I need to increment my program to provide an output table that displays the change in force as the distance changes. We&#8217;ve also recently discussed the boolean function, but I don&#8217;t know if it needs to (or can be) implemented into this program.<\/p>\n<p>Here&#8217;s what I have: (By the way, if anyone knows how to copy text out of Nano that would be lovely to know).<\/p>\n<p># include &lt;iostream&gt;<br \/>\n# include &lt;cmath&gt;<br \/>\n# include &lt;string&gt; &lt;&#8211; do I need this?<br \/>\nusing namespace std;<br \/>\nconst double G=6.673 * pow(10, -11) &lt;&#8211; can I do that?<br \/>\ndouble readDouble (string prompt)<br \/>\ndouble Force (double m_1, double m_2, double r, G);<\/p>\n<p>double Force (double m_1, double m_2, double r, G)<br \/>\n{<br \/>\nreturn m_1*m_2*G\/(pow(r, 2.0));<br \/>\n}<\/p>\n<p>double readDouble (string prompt)<br \/>\n{<br \/>\nbool done=False;<br \/>\nwhile (done=False)<br \/>\n{<br \/>\ncout&lt;&lt; &#8220;Enter mass of first object&#8221;;<br \/>\ncin&gt;&gt;m_1;<br \/>\ncout&lt;&lt; &#8220;Enter mass of second object&#8221;;<br \/>\ncin&gt;&gt; m_2;<br \/>\ncout&lt;&lt; &#8220;Enter initial distance between object&#8221;;<br \/>\ncin&gt;&gt;R_start;<br \/>\ncout&lt;&lt; &#8220;Enter final distance between objects&#8221;;<br \/>\ncin&gt;&gt;R_end;<br \/>\nif (cin.fail ()!=0<br \/>\n{<br \/>\ncout&lt;&lt;&#8220;Errot!&#8221;&lt;&lt;endl;<br \/>\ncin&gt;&gt;clear();<br \/>\ncin.ignore(INT_MAX, &#8216;\\n&#8217;);<br \/>\n}<br \/>\nelse<br \/>\ndone=true;<br \/>\n}<br \/>\nreturn 0;<br \/>\n}<\/p>\n<p>I&#8217;m sure this is atrocious. Any guidance would be greatly appreciated.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":1},"question-category":[55],"question_tags":[],"class_list":["post-12341","question","type-question","status-publish","hentry","question-category-programming"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/12341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=12341"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=12341"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=12341"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=12341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}