Thread: problem with structure, and parameter passing.

  1. #1
    Registered User
    Join Date
    Mar 2012
    Location
    Elkton, Florida, United States
    Posts
    5

    problem with structure, and parameter passing.

    My teacher marked off for the structure matching specs and correct parameter passing


    COP 2220Project 250 pointsDue electronically Friday, 2-17, at 8:00 a.m. Preliminary structure and IPO chart due Monday, February 6NOTE: From now on, the first output of all programs you write should be your name.Modify your program from Project 1 into a modularly designed program. Inaddition to the previously specified calculations, the program should alsocalculate the Kelvin temperature from the Fahrenheit (or more easily, the Celsius) and the feet to inches. Use a six-column report as shown in the example output.Display floating point values in the report using 3 places of precision. Kelvin should be double but inches should be int. Create the report with decimal places aligned correctly with the implied decimal of the integers. The resulting program *must* match the structure chart listed below.
    Code:
    .
                      main
                       |
       -----------------------------------
      |                |                  |
    getInput          calc             display
                       |
              --------------------
             |          |         |
        calcTemp  calcDistance  calcWeight
    and calcWeight *must* match the following prototype exactly. double calcWeight(int pounds);These requirements are worth significant points.This program is somewhat overmodularized but is an exercise in the different ways to pass data throughout functions in a program.

    Code:
    #include <stdio.h>
     
    void getInput (int* pFahr, int* pFeet, int* pLbs);
    void calcTDW (int fahr, int feet, int lbs);
    void calcTemp (int fahr, double* pCels, double* pKelvin);
    void calcDistance (int feet, double* pMeters, int* pInches);
    double calcWeight (int lbs);
    void display (int fahr, double cels, double kelvin, int feet, double 
                  meters, int inches, int lbs, double kilos);
     
    int main (void)
    {
       printf("Name: Bryan Benson");
       printf("\n\n");
       int fahr, feet, lbs, inches;
       double cels, meters, kilos;
       double kelvin;
     
       getInput (&fahr, &feet, &lbs);
       calcTDW (fahr, feet, lbs);
       calcTemp (fahr, &cels, &kelvin);
       calcDistance (feet, &meters, &inches);
       kilos = calcWeight (lbs);
       display (fahr, cels, kelvin, feet, meters, inches, lbs, kilos);
     
       return 0;
    }
     
    void getInput (int* pFahr, int* pFeet, int* pLbs)
    {
       printf ("Enter an integer value for Fahrenheit : ");
       scanf ("%d", pFahr);
       printf ("\nEnter an integer value for Feet : ");
       scanf ("%d", pFeet);
       printf ("\nEnter an integer value for Pounds : ");
       scanf ("%d", pLbs);
       printf ("\n\n");
    }
     
    void calcTDW (int fahr, int feet, int lbs)
    {
       void calcTemp (int fahr, double* pCels, double* pKelvin);
       void calcDistance (int feet, double* pMeters, int* pInches);
       double calcWeight (int lbs);
    }
     
    void calcTemp (int fahr, double* pCels, double* pKelvin)
    {
       *pCels = 5.0 * (fahr - 32) / 9.0;
       *pKelvin = *pCels + 273;
    }
     
    void calcDistance (int feet, double* pMeters, int* pInches)
    {
       *pMeters = 0.3048 * feet;
       *pInches = 12 * feet;
    }
      
    double calcWeight (int lbs)
    {
       double kilos;
      
       kilos = lbs / 2.204;
     
       return kilos;
    }
     
    void display (int fahr, double cels, double kelvin, int feet, double
                  meters, int inches, int lbs, double kilos)
    {
       printf ("\n  Original       Value  Converted to      Value  ");
       printf ("Converted to     Value    ");
     
       printf ("\n  --------       -----  ------------      -----  ");
       printf ("------------     -----    ");
     
       printf ("\nFahrenheit");
       printf ("%12d", fahr);
       printf ("       Celsius");
       printf ("%11.3f", cels);
       printf ("        Kelvin");
       printf ("%14.3f", kelvin);
     
       printf ("\n      Feet");
       printf ("%12d", feet);
       printf ("        Meters");
       printf ("%11.3f", meters);
       printf ("        Inches");
       printf ("%10d", inches);
      
       printf ("\n    Pounds");
       printf ("%12d", lbs);
       printf ("     Kilograms");
       printf ("%11.3f", kilos);
       printf ("\n\n");
    }
    Last edited by Salem; 03-10-2012 at 10:14 PM. Reason: Fixed your structure chart

  2. #2
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    What is your question?
    Code:
    while(!asleep) {
       sheep++;
    }

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well the basic problem is that your main is doing all the work of calculating, and that you didn't move all those calc.... calls into calcTDW.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structure Passing, Index Problem
    By ChipS in forum C Programming
    Replies: 11
    Last Post: 10-16-2011, 12:47 AM
  2. Replies: 10
    Last Post: 05-30-2011, 08:26 AM
  3. Replies: 4
    Last Post: 04-17-2011, 06:36 PM
  4. Problem Passing Structure Reference To Function
    By soj0mq3 in forum C Programming
    Replies: 9
    Last Post: 04-24-2010, 10:27 AM
  5. Problem passing double array as a function parameter
    By pppbigppp in forum C++ Programming
    Replies: 7
    Last Post: 06-06-2006, 03:08 AM