Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

<p>This program ask the user to enter his or her weight and the name of a planet

ID: 3625210 • Letter: #

Question

<p>This program ask the user to enter his or her weight and the name of a planet. The program was then to output how much the user would weigh on that planet. Rewrite this program so that the selection of the factor to use in computing the weight is made with a Switch statement instead of an if structure.The program should output an error message if the user doesn't type a correct planet name. The prompt and the error message should make it clear to the user how a planet name must be entered.</p>
<p>// Write a that asks the user to enter his or her weight and the name of a planet.</p>
<p>#include &lt;iostream&gt;&#160;</p>
<p>#include &lt;string&gt;</p>
<p>using namespace std;</p>
<p>int CheckWeight(int weight, string Planet);<br />int main()</p>
<p>{</p>
<p>int weight,res;</p>
<p>string planetName;</p>
<p><br />do{</p>
<p>cin.clear();</p>
<p>cout &lt;&lt; "Please enter your weight" &lt;&lt;endl;</p>
<p>cin &gt;&gt; weight;</p>
<p>}while(cin.good()==false);</p>
<p>cout &lt;&lt; " " &lt;&lt; endl;</p>
<p>do{</p>
<p>&#160;cout &lt;&lt; "Please enter a planet name from the following list" &lt;&lt; endl;</p>
<p>cout &lt;&lt; "Mercury, Venus, Earth, Moon, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto" &lt;&lt; endl;</p>
<p>cin &gt;&gt; planetName;</p>
<p>cout &lt;&lt; " " &lt;&lt; endl;</p>
<p>// Call function to check weight</p>
<p>res = CheckWeight(weight, planetName);</p>
<p>}while(res==1);</p>
<p>system("PAUSE");</p>
<p>return 0;</p>
<p>}// end main()</p>
<p><br />// Function for calculating weight</p>
<p><br />int CheckWeight(int weight, string Planet)</p>
<p>{</p>
<p>int Result=0;</p>
<p>if(Planet== "Mercury")</p>
<p>{</p>
<p>cout &lt;&lt; "Your weight on Mercury is " &lt;&lt; (weight*0.4155)&lt;&lt; endl;</p>
<p>}</p>
<p>else if(Planet== "Venus")</p>
<p>{</p>
<p>cout &lt;&lt; "Your weight on Venus is " &lt;&lt; (weight*0.8975)&lt;&lt; endl;</p>
<p>}</p>
<p>else if(Planet== "Earth")</p>
<p>{</p>
<p>cout &lt;&lt; "Your weight on Earth is " &lt;&lt; (weight*1.0)&lt;&lt; endl;</p>
<p>}</p>
<p>else if(Planet== "Moon")</p>
<p>{</p>
<p>cout &lt;&lt; "Your weight on Moon is " &lt;&lt; (weight*0.166)&lt;&lt; endl;</p>
<p>}</p>
<p>else if(Planet== "Mars")</p>
<p>{</p>
<p>cout &lt;&lt; "Your weight on Mars is " &lt;&lt; (weight*0.3507)&lt;&lt; endl;</p>
<p>}</p>
<p>else if(Planet== "Jupiter")</p>
<p>{</p>
<p>cout &lt;&lt; "Your weight on Jupiter is " &lt;&lt; (weight*2.5374)&lt;&lt; endl;</p>
<p>}</p>
<p>else if(Planet== "Saturn")</p>
<p>{</p>
<p>cout &lt;&lt; "Your weight on Saturn is " &lt;&lt; (weight*1.0677)&lt;&lt; endl;</p>
<p>}</p>
<p>else if(Planet== "Uranus")</p>
<p>{</p>
<p>cout &lt;&lt; "Your weight on Uranus is " &lt;&lt; (weight*0.8947)&lt;&lt; endl;</p>
<p>}</p>
<p>else if(Planet== "Neptune")</p>
<p>{</p>
<p>cout &lt;&lt; "Your weight on Neptune is " &lt;&lt; (weight*1.1794)&lt;&lt; endl;</p>
<p>}</p>
<p>else if(Planet== "Pluto")</p>
<p>{</p>
<p>cout &lt;&lt; "Your weight on Pluto is " &lt;&lt; (weight*0.0899)&lt;&lt; endl;</p>
<p>}</p>
<p>else</p>
<p>{</p>
<p>cout &lt;&lt; "You entered a wrong planet name. Please try again " &lt;&lt; endl;</p>
<p>cout &lt;&lt; " " &lt;&lt; endl;</p>
<p>Result=1;</p>
<p>}</p>
<p>return Result;</p>
<p>}<br /><br /></p>

Explanation / Answer

Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote