I'm trying to code a program that compares multiple values of two variables (CI and CF). CI contains one variable that can have 1 of 10 values, and CF contains variables which must be solved themselves (and one of these containing a variable that can have 1 of 3 values). After all the computing is said and done, I need to subtract CI from CF and output the values of CI, CF and CF-CI into three tables. I have included the code below. Note that all constants are listed, and the two variables that can have multiple values are 'thick' (1-10) and 'Tair' (-10, 0, 10). Also note that 'thick' + 'a' is actually variable 'b'. My problem is that 'b' and 'Tair' are found in a few equations, that will most likely be buried in functions. Code-wise, I've got it to a point, but to do what from here is where I'm stuck. Any help or suggestions are much appreciated.

// Project 2

#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cmath>
#include <math.h>
using namespace std;

const double a = 0.05;                 // Constants Declared
const double L = 100;                  // Constants Declared
const double Ta = 150;                 // Constants Declared
const double k = 0.1;                  // Constants Declared
const double F = 3.0;                  // Constants Declared
const double Cvol = 325;               // Constants Declared
const double CL = 1.50;                // Constants Declared
const double CstHeat = 0.00000000111;  // Constants Declared

double b(double thick);                // Function Declaration
double CI(double thick);               // Function Declaration
double Q3(double Tair);                // Function Declaration
double dQ(double Q3);                  // Function Declaration

double b(double thick)                  // Function 'b' Starts
{
       return (a+thick);
}

double CI(double thick)                 // Function 'CI' Starts
{
       return ((b(thick)*b(thick))-(a*a))*L*Cvol + (L+CL);
}

double Q3(double Tair)                  // Function 'Q3' Starts
{
       return (2*3.14*a*F*(Ta - Tair)*L);
}

int main ()                            // Main Function Start
{
    double thick;                      // Variables Declared
    double Tair;                       // Variables Declared
    
    double b(double thick);            // Call Function
    double CI(double thick);           // Call Function    
    double Q3(double Tair);            // Call Function
        
    for (thick = 1.0; thick <=10.0; thick +=1.0)       // for loop 
    {
        cout << CI(thick) << endl;
        }

    for (Tair = -10; Tair <=10; Tair +=10)
    {
        cout << Q3(Tair) << endl;
        }
        
        system ("pause");
}

My problem is that 'b' and 'Tair' are found in a few equations, that will most likely be buried in functions.

I'm not sure what the problem is from this description. Sounds like you are worried that the compiler will confuse variable names and function names? Do you get those kinds of errors? You can always rename or a function so they are slightly different (for example, the variable starts with a lower case letter and the function with a capital letter) so the compiler (and people) can distinguish between the two.

Your description of "thick" and "Tair" make me think that these should be integers, not doubles. Also, in your for-loops, you have the (probably unlikely in your case but still possible) possibility of a round-off error in that you are basically comparing doubles to an exact number in these loops. Any round-off error in the wrong direction could potentially cause the loops to execute one extra time or one time too few. Again, unlikely with your particular numbers, but still something to consider.

Actually, I believe I got it now. My problem was that I was trying to use a function in another equation as a variable...now I just have to figure out how to display my results as a table...I need to put CF, CI and CF-CI into a table, based on the values Tair and Thick...

This article has been dead for over six months. Start a new discussion instead.