Solved

weight

Posted on 1997-05-21
6
399 Views
Last Modified: 2012-06-21
I am a beginner in C and am trying to write the following program that will compute a person's weight on the following planets.
PLANET                  PERCENTAGE OF EARTH WEIGHT
EARTH                   100
MOON                    16
JUPITER                 264
VENUS                   85
MARS                    38
Create a printed table of weights ranging from 50 to 250 pounds in steps 0f 10 pounds. Place "Weight and Planet Headers" across the top of the page and print the table with the weights running topo to bottom.
0
Comment
Question by:barn
  • 3
  • 2
6 Comments
 

Author Comment

by:barn
ID: 1250497
Edited text of question
0
 

Author Comment

by:barn
ID: 1250498
Edited text of question
0
 

Expert Comment

by:cwestin
ID: 1250499
What are you asking?  Do you just want someone else to write this for you?  Is this for a class?
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 10

Accepted Solution

by:
RONSLOW earned 100 total points
ID: 1250500
Sounds like a class assignment to me :-)

so you want something like:

/* these are our planets */
typedef enum {
  EARTH, MOON, JUPITER, VENUS, MARS
} Planet;

void main () {
  /* here are the names of the planets */
  char* name[] = {"Earth","Moon","Jupiter","Venus","Mars"};
  /* here are the percentage of earth weight for each planet */
  int percentage [] = { 100,16,264,85,38 };
  int earth_weight;

  /* heading line */
  printf("\tWeight and Planet\n");

  /* columns heading - one per planet */
  for (planet = EARTH; planet <= MARS; planet++) {
    printf("%8.8s",name[planet]);
  }
  printf("\n");

  /* each row is a different weight */
  for (
    earth_weight = 50;
    earth_weight <= 250;
    earth_weight += 10
  ) {
    enum Planet planet;
    /* calculate actual weight for each planet and print */
    for (planet = EARTH; planet <= MARS; planet++) {
      int weight = earth_weight*percentage[planet]/100;
      printf ("%8d",weight);
    }
    /* end of line */
    printf ("\n");
  }
}

Any questions??

0
 

Author Comment

by:barn
ID: 1250501
Thank you for the help.
I tried to run your program and got 3 error messages.
1. Declaration syntax error in function main.
2. Undefined symbol 'planet' in function main.
3. Undefined symbol 'earth_weight' in function main.

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1250502
OK - little syntax error :-)

Couldn't you have fixed this yourself - I just typed in a program off the top of my head - didn't know you wanted my to debug it as well !! - only problem was that I had the declaraion of Planet

Here is a version that compiles on my compiler

#include <stdio.h>

/* these are our planets */
typedef enum Planet {
      EARTH, MOON, JUPITER, VENUS, MARS
} Planet;

void main () {
      /* here are the names of the planets */
      char* name[] = {"Earth","Moon","Jupiter","Venus","Mars"};
      /* here are the percentage of earth weight for each planet */
      int percentage [] = { 100,16,264,85,38 };
      int earth_weight;
      Planet planet;
      
      /* heading line */
      printf("\tWeight and Planet\n");
      
      /* columns heading - one per planet */
      for (planet = EARTH; planet <= MARS; planet++) {
            printf("%8.8s",name[planet]);
      }
      printf("\n");
      
      /* each row is a different weight */
      for (
            earth_weight = 50;
      earth_weight <= 250;
      earth_weight += 10
            ) {
            /* calculate actual weight for each planet and print */
            for (planet = EARTH; planet <= MARS; planet++) {
                  int weight = earth_weight*percentage[planet]/100;
                  printf ("%8d",weight);
            }
            /* end of line */
            printf ("\n");
      }
}

Hope this works better for you - if not, then I cannot help because it compiles fine with no warnings etc on my compiler.  You will need to get any other bug out yourself - that is how you LEARN !!!

Roger

0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to declare a 2-dimensional version of strlen 4 217
Convert image to byte array 8 208
mixing C++ and C code elegantly 10 158
c++ getting the first 10 characters of a char* string 11 98
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question