How to make a table

This is a discussion on How to make a table within the C++ Programming forums, part of the General Programming Boards category; I've been having trouble all day, and been slaving over this program. Quick Intro: This program computes overall heat loss ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    4

    How to make a table

    I've been having trouble all day, and been slaving over this program.
    Quick Intro: This program computes overall heat loss of a cylindrical tank, depending on multiple measurements. I need this program to display height on the left and radii on the top, and then display the heat loss in a form of a table. I hit a major wall as soon as i began. The *for* loop i'm using is not doing what i want it to do, and i know why, but not know how to fix it. I need it to start at user specified height/ radius and then increase by user specified increment to user specified values.

    Example: I pick 30 feet, 10 values to be displayed, and 1 feet increments
    my loop is just infinite, as it wont stop at a user specified value
    here's my loop

    Code:
     { 
             for(height = height; height>=0; height+=x)
        cout << height <<"  " << endl;
    }
    and here's the whole code

    Code:
     /* This program was made by Andrew Arellano on 1/25/2010 */
    
    #include<iostream>
    #include<cmath>
    #include<windows.h>
    #include<iomanip>
    using namespace std;
    int main()
    {
        system("color 02");
        
        cout <<"Andrew Arellano\n";
        cout <<"659806045\n\n";        
        cout <<"This program calculates the overall rate of heat loss from a \n";
        cout <<"cylindrical tank, given the dimensions of the tank, the thermal \n";
        cout <<"conductivity of the tank walls, and the internal and external temperatures.\n\n";
             Sleep(5000);
        
        //Declare all variables    
        double rate_heat (0.0), thermal (0.0), thick (0.0), hot (0.0), cold (0.0), rate_radial (0.0);
        double height (0.0), radius_in (0.0), radius_wall (0.0), area (0.0), thick_feet (0.0), rate_total (0.0);
        const double PI = 3.141593;
        double n_value (0.0), x (0.0), x_rad (0.0), x_value (0.0);
        
        cout <<"Please enter in the thickness, in inches, of the tank wall\n";
        cin >> thick;
        cout <<"\n";
        
        cout <<"Please enter in the thermal conductivity, in BTU/hr ft deg F.\n";
        cin >> thermal;
        cout <<"\n";
        
        cout <<"Please enter in the temperature, in degress Farenheit, inside the tank\n";
        cin >> hot;
        cout <<"\n";
        
        cout <<"Please enter in the temperature, in degrees Farenheit, outside the tank\n";
        cin >> cold;
        cout <<"\n";
        
        cout <<"Please enter in the range of height, in feet, of the tank; beginning with a minimum value\n";
        cin >> height;
        cout <<"\n";
        
        cout <<"Please enter in the number of values of height to be recorded\n";
        cin >> n_value;
        cout <<"\n";
        
        cout <<"Please enter in the increment value\n";
        cin >> x;
        cout <<"\n";
        
        cout <<"Please enter in the range of inside radii, in feet, of the tank; beginning with the minimum value\n";
        cin >> radius_in;
        cout <<"\n";
        
        cout <<"Please enter in the number of values of radius to be recorded\n";
        cin >> x_value;
        cout <<"\n";
        
        cout <<"Please enter in the increment value\n";
        cin >> x_rad;
        cout <<"\n";
    
        { 
             for(height = height; height>=0; height+=x)
        cout << height <<"  " << endl;
    }
    
        
        
        
        //Perform necessary calculations (rate of heat loss through the top).
        area = 2 * radius_in * PI * height; // area=2*pi*inside radius*height
        rate_heat = ((thermal * area) / thick) * ( hot - cold); //rate of heat loss through the top = ((thermal conductivity * area) / wall thickness)*(hot temp - cold temp)
        
        //Perform necessary calculations (rate of heat loss through the sides).
        thick_feet = thick/12; //Wall thickness/12 in order to convert it to feet
        radius_wall = (radius_in + thick_feet) / (radius_in); //Radius (wall thickness included) / inside radius
        rate_radial = ((2 * PI * thermal * height) / (log(radius_wall))) * (hot - cold); // side heat loss = (2*pi*thermal*height / natural log radius+thick) * (hot-cold)
        
        //Perform necessary calculations (total amount of heat loss).
        rate_total = rate_heat + rate_radial; //total heat loss = top heat loss + side heat loss
        
        // min, values, increments
        
        
        //Print user inputs
        cout <<"According to your inputs\n";
        cout << height <<" feet high\n";
        cout << radius_in <<" feet (radius)\n";
        cout << thick <<" inches thick\n";
        cout << thermal <<" BTU/hr ft deg. F\n";
        cout << hot <<" degrees Farenheit\n";
        cout << cold <<" degrees Farenheit\n\n";
             Sleep(5600);
        
        //Print results
        cout <<"The heat loss through the top is " << rate_heat <<" BTUs\n";
        cout <<"The heat loss through the sides of tank is " << rate_radial <<" BTUs\n";    
        cout <<"And, the total rate of heat loss is " << rate_total <<" BTUs\n\n";
        
        system("pause");
        return 0;
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,765
    > for(height = height; height>=0; height+=x)
    Well let's assume you want to start at 0, and work your way up to height.

    Code:
    for ( h = 0 ; h < height ; h += x ) {
      cout << "Do work for height = " << h << endl;
    }
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    4
    i think i've found what i've been looking for, for the past 36 hours. i think i can use multi-dimensional arrays to create the table i need. but i keep getting the error size of array 'rad' has non-integral type double

    if anyone can help me please thx

  4. #4
    Registered User
    Join Date
    Feb 2010
    Posts
    4
    ok i got rid of the error but i dont know how to make the table, and also note: i want the table to be made according to user input

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,765
    We've no idea what you've done to the code.

    > i want the table to be made according to user input
    What does that mean?
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Feb 2010
    Posts
    4
    sorry bout that, i mean if the user wants 10 values of height to be recorded i want it to increment the inital height 10 times, but i'm on to something different now, i figured out im going to ask the user for a min. value and a max. value and increment until the min reaches the max

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. trying to make a hash table......trouble w/ memory?
    By cuizy in forum C Programming
    Replies: 3
    Last Post: 05-11-2009, 05:47 PM
  2. Duplicate at Hash Table
    By DarrenY in forum C Programming
    Replies: 1
    Last Post: 05-10-2007, 03:31 AM
  3. Win32 Common Controls in C++, how do i make and use them?
    By C+noob in forum Windows Programming
    Replies: 6
    Last Post: 01-09-2006, 11:53 AM
  4. how do i make a mathematical table using loops.
    By gad n' gaz in forum C Programming
    Replies: 13
    Last Post: 10-18-2005, 03:15 PM
  5. How to make a multiplication table up to 10*10=100?
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 01-11-2002, 10:07 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21