Making a table with range of values

I'm fairly new to programming, and i've run into a little wall haha. I need to make a table reporting maximum heat loss displaying height on the top, and radii on the left. both values begin with a minimum value then increase to x values depending on the user input. I need help with the looping, and where to put the loop and how? THX, all help appreciated.

Heres my code- (This code is the first part, which was to just report the heat loss)

/* 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";



//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



//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;
}
1: Please use code tags and proper formatting: (http://www.cplusplus.com/articles/firedraco1/)
2: Never use system(): (http://www.cplusplus.com/forum/articles/11153/)
3: Loop tutorials: http://www.cplusplus.com/doc/tutorial/control/
thx alot Dr loop tutorials helped me out haha it looks like i gotta use a for loop

ur post wont let me open 1 & 2 tho, and i'm using system("pause") becasue i'm using Dev C++
hey im having trouble with the same issue
is it possible if u can post your code including the do while part
is it possible if u can post your code including the do while part


No, if you want help, post you current code here with an attempt at loops(and read the tutorials first)

@Zero
Here are the first and second links again:
Code tags: http://www.cplusplus.com/articles/firedraco1/
System() :http://www.cplusplus.com/forum/articles/11153/

They both should work now.
Last edited on
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{


double thermalcond , wallthick , tempinside,
tempoutside , heattransfer1, radialheattransfer, totalheat;
int tankheight_initial,
tankheight_increment ,tankheight_final, radius_initial,radius_increment,
radius_final;
const double PI = 3.14159;




// input and output
cout << " Please enter the thickness of the tank in inches \n";
cin >> wallthick;

cout << " \nEnter the thermal conductivity of walls in Btu / hr ft deg F\n\n";
cin >> thermalcond;

cout << " \nEnter the temperature inside the tank in Fahrehite degrees\n\n";
cin >> tempinside;

cout << " \nEnter the temperature outside the tank in Fahrenhite degrees\n\n";
cin >> tempoutside;

cout << "\nEnter the initial value for the tank height in feet\n\n";
cin >> tankheight_initial;

cout << "\nEnter the increment between the heights in feet";
cin >> tankheight_increment;

cout << "\nEnter the final value for the tank height in feet\n\n";
cin >> tankheight_final;

cout << "\nEnter the intial value for the radius of the tank in feet\n\n";
cin >> radius_initial;

cout << "\nEnter the increment between the radii in feet\n\n";
cin >> radius_increment;

cout << "\nEnter the final value for the tank radius in feet\n\n";
cin >> radius_final;

//end of input and output

// Table and output for program

cout << " Maximum heat loss (MBtu/hr) \n";
cout << "Tank Height(ft) Tank Radius(ft) \n";




do
{
int loops = (tankheight_final-tankheight_initial)/tankheight_increment+1;
int radiusloop = radius_initial + count * radius_increment;


} while (int count = 0; count < loops; count++)


do
{ int loops = (tankheight_final-tankheight_initial)/tankheight_increment+1;
int heightloop = tankheight_initial + count * tankheight_increment;

} while (int count = 0; count < loops; count++)


do
{ int loops = (tankheight_final-tankheight_initial)/tankheight_increment+1;
heattransfer1 =(((thermalcond*PI*radiusloop*radiusloop)/(wallthick/12))*(tempinside-tempoutside))/1000;

} while (int count = 0; count < loops; count++)


do
{ int loops = (tankheight_final-tankheight_initial)/tankheight_increment+1;
radialheattransfer = ((2*PI*thermalcond*heightloop*(tempinside-tempoutside) / log((radiusloop+(wallthick/12))/radiusloop)))/1000000;

} while (int count = 0; count < loops; count++)



do
{ int loops = (tankheight_final-tankheight_initial)/tankheight_increment+1;
totalheat = (heattransfer1/1000)+(radialheattransfer);

} while (int count = 0; count < loops; count++)

return (0);
system ("pause");

}
thx alot for helping me with this code, but for some reason the one you gave me isn't working
Typically you should ignore posts from people of post count less than 100, Not saying you should ignore ALL, just some obvious ones. Because chances are they will hinder you rather than help, that said. Could you post what you have done so far in code tags, or perhaps ask us specific questions as to what you are stuck on and we would be glad to help.
well, taking this one step at a time, im trying to display radii across the top beginning with the user initial input and then incrementing to a user defined value example:

user inputs starting value 30 for radius for a total of 10 values in increments of 1, or whatever

the for loop i tired is infinite and doesnt even increase, haha i've been at this allllllll day and have been progressing so little

heres the loop i tried:


for( height==height; n_value; height + x);
cout << height;


thats what i put after the calculations,
note: height is the inital height value, n_value is how many values of height the user wants calculated, and x is the increment number. I need radii on the top and height on the left, but i'm trying to get the loop going for the first line.

all help appreciated
well height should be initialized to 0 if you want the loop to increment, as it is at the moment an infinite loop due to the condition. For loops work like this:

for ( initialization ; condition ; increment )
1, 2 or 3 of the section can be blank, but having a condition such as n_value will not check anything.

So say n_value = 5; then all the loop is doing is checking the initialization which is fine, height = height ;
then the condition n_value which is true because it is not void. Then it is incrementing height, and checking the condition again which is true because n_value still equals 5.... infinite.

This loop will count to ten:

for ( int i = 0; i < 10; i++ )
cout << i << endl;

first pass, i is zero, the condition is true 0 is less than 10, so it prints out 0;
2nd pass, i gets incremented to 1, condition is true 1 less than 10, so it prints 1;
3rd is 2, condition true 2 less than 10, so prints 2..
and so on...
Last edited on
i understand the example you gave, but its just i want the first number displayed to be
user input height, and then increment to user specified number of values,
im getting somewhere now haha

{
for (height=0.0; height>0; height+=x)
cout << height << endl;
}

now its not incrementing, but since height > 0, its not incrementing to the user specified number of values the user wants, but im getting a lil closer lol
im stuck man, im going crazyyy, taking a break
that's now not even going to work because the initialization will happen : height = 0;
then the condition will check: height greater than 0, which is false. thats the end.

I've been busy babysitting, but I'll try and look at the actual problem you need to solve later on when I get some time, or hopefully someone else can give you some guidance.
thx for the help, but yeah, i ran it with that infinite loop and it kept adding whatever x was, and in my input, 1,
got the same problem. my code is below. i have no idea how to create this "multiplication table" of values. i believe u are supposed to use variables for # of columns and rows.



// Declare variables to be used
double height (0.0), insideR(0.0), thick(0.0), thermCond(0.0), MaxHeight(0.0), MaxRadius(0.0),
outsideT(0.0), insideT(0.0), qW(0.0), qR(0.0), q(0.0), area(0.0), outsideR(0.0), minHeight(0.0),
NumHeights(0.0), IncHeight(0.0), minRadius(0.0), NumRadii(0.0), IncRadii(0.0), NumRows(0.0), NumColumns(0.0);
const double PI = 3.14159;
//Explain to the user what the program does
cout<< " \n";
cout<< "This program presents a table of maximum heat loss for a cylindrical tank,\n";
cout <<"given a minimum value of ";
cout<< "height & radius, number of values for each, and\nthe increment.\n\n";

//Get user input
cout<< "Please enter the thickness of the tank in inches >";
cin>> thick;
cout<< "Please enter the thermal conductivity of the tank walls in Btu/(hr*ft*deg F) >";
cin>> thermCond;
cout<< "Please enter the temperature inside the tank in fahrenheit >";
cin>> insideT;
cout<< "Please enter the temperature outside the tank in fahrenheit >";
cin>> outsideT;

do { //loop if input is incorrect
cout<< "Please enter the minimum height value >";
cin>> minHeight;
if ( minHeight <= 0 )
cerr<< "\nMinimum height cannot be <= 0 or > 25.\n\n"; //Error message for bad input
} while ( minHeight <= 0 );

do { //loop if input is incorrect
cout<< "Please enter the number of heights >";
cin>> NumHeights;
if ( NumHeights <= 0)
cerr<<"\nNumber of heights cannot be <= 0 or > 25.\n\n";
} while ( NumHeights <= 0 || NumHeights > 25);

do {
cout<< "Please enter the increment of height >";
cin>> IncHeight;
if ( NumHeights > 1 && IncHeight <= 0)
cerr<< "\nIncrement of height cannot be <= 0 when your number of heights is > 1\n\n";
} while ( (NumHeights > 1 && IncHeight <= 0) || IncHeight < 0 || IncHeight > 25);

do {
cout<< "Please enter the minimum radius value >";
cin>> minRadius;
if (minRadius <= 0)
cerr<< "\nRadius cannot be less than or equal to zero.\n\n";
} while (minRadius <= 0);

do {
cout<< "Please enter the number of radii >";
cin>> NumRadii;
if ( NumRadii <= 0)
cerr<< "\nNumber of radii cannot be less <= 0 or > 25.\n\n";
} while ( NumRadii<= 0 || NumRadii > 25);

do {
cout<< "Please enter the increment of radii >";
cin>> IncRadii;
if ( NumRadii > 1 && IncRadii <= 0)
cerr<< "\nIncrement of radii cannot be <= 0 when your number of radii is > 1.\n\n";
} while ( (NumRadii > 1 && IncRadii <= 0) || IncHeight < 0 || IncHeight > 25);
//Calculate Maximum and minimum height and radii
MaxHeight=minHeight + (NumHeights-1)*IncHeight;
MaxRadius=minRadius + (NumRadii-1)*IncRadii;

for ( height=minHeight; height<=MaxHeight; height=IncHeight+height)
{
for( insideR=minRadius; insideR<=MaxRadius; insideR=IncRadii+insideR)
{
thick = thick/12;
outsideR = insideR + thick;
area = PI * (insideR * insideR);
qW = (thermCond * area *(insideT-outsideT)) / thick;
qR = (2*PI*thermCond*height*(insideT-outsideT)) / log(outsideR / insideR);
cout<< setw(10) << qR << endl;
}
}



system ("pause");
return 0;

}
thx alot for the error messages, as i never even thought about that, but yeah I need it to loop until a user specified number. quick question... are you making this same program too???
Topic archived. No new replies allowed.