Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: Help with p...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 5 Topic 45802 of 46738
Post > Topic >>

Re: Help with program using multiple functions/variables

by "Alf P. Steinbach" <alfps@[EMAIL PROTECTED] > May 8, 2008 at 03:10 AM

* mattyizzo@[EMAIL PROTECTED]
> Here is my code. Basically I'm trying to solve for CI and CF, where
> each use a bunch of constants and a variable or two which can have up
> to 10 values. I get the following error, however, at line 39:
> 
> 39 H:\Project 2-PartialComplete5-7.cpp invalid operands of types
> `double ()(double)' and `const double' to binary `operator/'
> 
> The error itself is at the equation starting with dQ = ... Any ideas,
> suggestions?
> Here is my code:
> 
> // 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

Here you declare b as a function.


> double CI(double thick);               // Function Declaration
> double CF(double thick, double Tair);  // 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 CF(double thick, double Tair)     // Function 'CF' Starts
> {
>        double Q3;
>        double dQ;
> 
>        Q3 = 2*3.14*a*F*(Ta-Tair)*L;
>        dQ = Q3*(1-((b/a)/(1+((b*F)/k*(log(b/a))))));

Here you try to divide the function b by a.


>        return dQ*(157800000)*(CstHeat);
> }
> 
> 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

As a general rule, don't declare functions inside other functions.


> 
>     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");
> }

Cheers, & hth.,

- Alf


-- 
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 




 5 Posts in Topic:
Help with program using multiple functions/variables
mattyizzo@[EMAIL PROTECTE  2008-05-07 18:02:10 
Re: Help with program using multiple functions/variables
"Alf P. Steinbach&qu  2008-05-08 03:10:38 
Re: Help with program using multiple functions/variables
mattyizzo@[EMAIL PROTECTE  2008-05-07 18:26:19 
Re: Help with program using multiple functions/variables
Krice <paulkp@[EMAIL P  2008-05-08 03:41:28 
Re: Help with program using multiple functions/variables
mattyizzo@[EMAIL PROTECTE  2008-05-08 06:14:01 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 9 0:17:08 CDT 2008.