Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Programming in C with comments/steps 1. Overview The purpose of this assignment is to give you some experience with writing functions that take in arguments
Programming in C with comments/steps
1. Overview The purpose of this assignment is to give you some experience with writing functions that take in arguments and return values, as well as writing a program that consists of multiple files. This assignment also requires the use of a switch statement, in addition to more practice with printf& scanf declaring variables, using loops, and using logical expressions. For this assignment, you will prompt the user in the main function to enter their weight (in pounds). Also you will prompt the user to enter an integer corresponding to a planet (or solar body). Another function, which will reside in a separate .c file, will be called, sending those two inputs. In that function, a switch statement will be used to determine how much the person would weigh on that other planet and that result will be returned to the main function where it was called from. Then the result will be shown to the user. 3. More Specifics Your program will have a second function called otherWeight. That function will take in 2 integer arguments: the weight of the person, and an integer representing their planet of choice (See the table below), and return an integer In that other function called otherWeight, you will use the integer for the planet in a switch statement. There are 8 choices the person can make, so there should be at least 8 cases in the switch statement one for each number between 1-8, plus a default case (although, in this case, it might just make sense to make the 8h case the default). Using the values in the table below in the switch statement for each corresponding planet, calculate the new weight for that planet and return it back to the main function. Back in the main) function after that new weight has been returned from the otherWeight 0 function, use a print statement to show the results. CHOICE SOLAR BODY GRAVITY FACTOR 0.284 0.907 Mars 0.38 34 0.925 0.795 1.125 0.166 4 Jupiter Saturn Uranus 7 Neptune the Moon So, if a person enters 125 for their weight, and the number 7, which corresponds to Neptune, your program will tell them that on Neptune, they would weigh 140 pounds (or if you want to use floats, you could tell them that their weight on Neptune would be 140.63 pounds). You should also use a loop in the main function so that the program keeps running until the user enters a 0 indicating they are done. (See sample output on the next page). And lastly, you should check for valid input. If the user enters something that is not a 1 or a0, the program should prompt then again until valid input is entered. Your program should also include a h file, called defs.h, where the function prototype for the otherWeight function should reside, along with the include Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started