Answered step by step
Verified Expert Solution
Link Copied!

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
image text in transcribed
image text in transcribed
image text in transcribed
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 statement. That defs.h file should be #included in your other 2 files. The file that contains the main() function should be named main.c. otherWeight ) function should be named otherWeight.c The file that contains the As with all your programming assignments, your program should compile without warnings and run correctly on the computer science Unix named machines. Your code will be evaluated not only on its correctness but also on the cleanliness of your code. Make sure your program has good programming style (Programming Assignment Requirements handout is provided on Blackboard under Handouts and Other Info) and that you use meaningful variable names. Don't forget about indentation and comments. 4. Sample Output The following is a sample run where user input is denoted in bold italics. Your statements to the user don't have to be exactly what I have below, as long as they are something that is informative to the user as to what is needed and what is going on. The program results to the user also don't have to look exactly as mine below; I tweaked mine in a way to make it easy to see what the results are use your own creativity to "fancy it up" if you want. But your program should work the same as what is shown below Enter your weight in pounds: 125 Which planet do you want to see how much you would weigh on? 1: Mercury 2: Venus 3: Mars 4: Jupiter 5: Saturn 6: Uranus 7: Neptune 8: the Moon On Mercury, you would weigh 35.50 pounds! Do you want to go again? (1 for Yes, 0 for No) 2 Do you want to go again? (1 for Yes, 0 for No) Which planet do you want to see how much you would weigh on? 1: Mercury 2: Venus 3: Mars 4: Jupiter 5: Saturn 6: Uranus 7: Neptune 8: the Moon 2 On Venus, you would weigh 113.38 pounds! Do you want to go again? 1 for Yes, 0 for No)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

3. Comment on how diversity and equality should be managed.

Answered: 1 week ago

Question

describe the legislation that addresses workplace equality

Answered: 1 week ago