Question
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 r
3. More Specifics Your program will have a second function called otherWeight. That function will take in 2 integer arguments
4. Sample Output The following is a sample run where user input is denoted in bold italics. Your statements to the user dont
0 0
Add a comment Improve this question Transcribed image text
Answer #1

====================================================================

File1: defs.h

--------------------------------------------------------------------

#include <stdio.h>

/*

First arg: weight of the person

Second arg: choice of the planet

Return: weight on the selected planet

*/

float otherWeight(int, int);

=================================================================

File2: otherWeight.c

------------------------------------------------------------------------------

#include "defs.h"

/*

First arg: weight of the person

Second arg: choice of the planet

Return: weight on the selected planet

*/

float otherWeight(int weight, int planet) {

    // Switch case

    switch(planet) {

        case 1: // for mercury

            return weight * 0.284;

            // No need of break statement as we are using return statement

        case 2: // for Venus

            return weight * 0.907;

            

        case 3: // for Mars

            return weight * 0.38;

           

        case 4: // for Jupiter

            return weight * 2.34;

           

        case 5: // for Saturn

            return weight * 0.925;

           

        case 6: // for Uranus

            return weight * 0.795;

           

        case 7: // for Neptune

            return weight * 1.125;

           

        default: // 8th case for the moon

            return weight * 0.166;

           

    }

}

=================================================================================

File 3: main.c

---------------------------------------------------------------------------------

#include "defs.h"

int main() {

    int weight, planet; // User input

    float weightOnPlanet; // variable for calculated weight on other planet

    // for printing planets names.

    char planets[8][10] = {"Mercury" ,"Venus", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "The Moon"};

    int choice = 0;

    printf("Enter your weight in pounds: ");

    scanf("%d", &weight);

    do { // Loop until user says go again (yes)

       

        printf("\nWhich planet do you want to see how much you would weigh on? \

                \n1: Mercury \

                \n2: Venus \

                \n3: Mars \

                \n4: Jupiter \

                \n5: Saturn \

                \n6: Uranus \

                \n7: Neptune \

                \n8: The Moon \

                \nEnter your choice: ");

        scanf("%d", &planet);

        // Call function to get the weight on other planet

        weightOnPlanet = otherWeight(weight, planet);

        //Array index start with 0. So, we use planet-1

        printf("\nOn %s, you would weigh %.2f pounds!", planets[planet-1], weightOnPlanet);

        // Loop until valid input i.e. 1 or 0

        do {

            printf("\n\nDo you want to go again? (1 for Yes, 0 for No) : ");

            scanf("%d", &choice);

           

        } while(choice != 1 && choice != 0);

    } while(choice == 1);

    return 0;

}

================================================================================

Sample Output:

HomeworkLib@SurfaceProVRS:/mnt/c/Users/sekha/OneDrive/Dev/c$ gcc main.c otherWeight.c HomeworkLib@SurfaceProVRS:/mnt/c/Users/sekha/OneDri

Add a comment
Know the answer?
Add Answer to:
Programming in C with comments/steps 1. Overview The purpose of this assignment is to give you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • So i need help with this program, This program is supposed to ask the user to...

    So i need help with this program, This program is supposed to ask the user to input their weight on earth so I would put "140" then it would ask "enter planet name, Min, Max or all" and if the user typed in all it would display all the planets and your weight on them. Right now Im suck on the part where im required to do a switch statement with a linear search. Below this im going to put...

  • VISUAL STUDIO - WINDOWS FORM APP (C#) - PLEASE MAKE SURE TO SHOW ALL CODE &...

    VISUAL STUDIO - WINDOWS FORM APP (C#) - PLEASE MAKE SURE TO SHOW ALL CODE & ANSWER/FOLLOW ALL THE QUESTIONS IN THE ASSIGNMENT! Planet Info Help When planning this project, review the concept of accessing object properties on another form. Form2.IblMessage.Text = "1122.25" or you can put a string or object instead of numbers You can then create one form for the Planets information and set all the properties before you display the Planet Form For the pictures of the...

  • Before you start doing this code Read carefully there is a format that you have to...

    Before you start doing this code Read carefully there is a format that you have to follow HERE IS THE FORMAT YOU MUST USE FOR HW #2 - NOTE THE IF ELSE IF...not IF IF IF HW #2 Format : Instructions: This program will generate some information for a user about interplanetary travel (pretend we can travel easily to other planets for this problem). This program will perform calculations concerning weight on various planets as well as travel time between...

  • INSTRUCTIONS #6. Your science teacher has asked you to create an application that displays how much...

    INSTRUCTIONS #6. Your science teacher has asked you to create an application that displays how much a person would weigh on the following planets: Venus, Mars, and Jupiter. The application's interface should allow the user to enter the person's weight on Earth. Perform the steps involved in creating an OO application. (See the Note at the beginning of the Exercises section.) Include a button for clearing the screen. . Create an application, using the following names for the solution and...

  • A well-known feature of our solar system is the asteroid belt between Mars and Jupiter. One...

    A well-known feature of our solar system is the asteroid belt between Mars and Jupiter. One theory about the asteroid belt is that it's made of primordial material that was prevented from forming another planet by the gravitational pull of Jupiter when the solar system was formed. One of the largest asteroids is 951 Gaspra. Its distance from the Sun is 207.16 million miles. Use your linear regression equation to interpolate the length of its sidereal year. Please take the...

  • In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a...

    In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter an integer value. Your program will then display that integer back to the user. Your program should include a function called getInteger that requests an integer value from the user and returns that value back to the caller. Your main () function will call the function getInteger and will then display the value returned by that function....

  • Q4. Because of your physics skills you have been selected to scout locations for the first movie ...

    need answer ASAP. Do not know how to caculate answers. Q4. Because of your physics skills you have been selected to scout locations for the first movie to be shot or another planet. However while there an alien sneaks up behind you and hits you on the head. When you wake up you cannot remember what planet you are on, but you do have a table of gravitational acceleration on the different planets and a ball you can throw. Use...

  • Part 1 The purpose of this part of the assignment is to give you practice in...

    Part 1 The purpose of this part of the assignment is to give you practice in creating a class. You will develop a program that creates a class for a book. The main program will simply test this class. The class will have the following data members: A string for the name of the author A string for the book title A long integer for the ISBN The class will have the following member functions (details about each one are...

  • daily21. Computing 1. C programming Please provide comments and write pre-condition and post-condition for the function....

    daily21. Computing 1. C programming Please provide comments and write pre-condition and post-condition for the function. Description Create a project called Daily21. Add a source file called daily21.c into the project. In this exercise, you will practice working with an array of integers. In the main function, you first need to create an integer array with 10 elements in t. Use a loop to read 10 integers from the user and store the values to the array (in the order...

  • C++ Programming

    PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT