Problem with functions

This is a discussion on Problem with functions within the C++ Programming forums, part of the General Programming Boards category; I'm having some problems with fuctions could someone please get me going in the right direction. thanks Code: #include <iostream> ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    14

    Problem with functions

    I'm having some problems with fuctions could someone please get me going in the right direction. thanks

    Code:
    #include <iostream>
    #include <iomanip>
    #include <cmath>
    
    
    using namespace std;
    
    const int row=12, col=18;
    
    void windchill (double temp[][windspeed]);
    void print_wind (double n[][col]);
    
    int main()
    
    {
    	double temp,
    		windspeed;
    
    
        windchill (temp);
    
        print_wind (windchill);
    
    	return 0;
    
    }
    
    
      void windchill (double temp[],[windspeed])
    
      {
    	  double t,
    		  v,
    		  chill;
    
         for ( t = 40;t <= -45;t -= 5 )
    		 for ( v = 5; v <= 60; v += 5)
    		 {
    			 chill = 35.74+0.6215(t)-35.75(v ^ 0.16)+0.4275(t)(v^0.16)
    		 }
    		
    
      }		
    		
    		
    		
    		
    		
    		
    void print_wind (double n[][col])
    
    {
    
    	int i,j,t,v;
    	cout << "\t\t    Wind Speed in MPH / Temperture in F \n\n";
    	for (i=0,t=40;i<col;i++,t-=5);
    	cout << setw(4) << t;
    	cout << "\n\n";
    	for (i=0,v=5;i<row;j++,v+=5);
    	{
    		cout << setw(2) << v;
    		for (j=0;j<col;j++)
    			cout << setw(4) << n[i][j];
    		cout << "\n";
    }
    }

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Your main problem is in passing variables to functions. If you've never used functions before, I'd strongly advise against trying to pass arrays until you understand how to pass ints and such. Have you read the tutorials here? Specifically, read "Functions" and then read "Pointers" and then "Arrays"
    Away.

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    14

    precision

    Ok i got my programm working, but the temp are still not coming out right. could someone help me in the right direction.
    thanks


    Code:
    #include <iostream>
    #include <iomanip>
    #include <cmath>
    
    
    using namespace std;
    
    const int row=12, col=18;
    
    void windchill (double [][col]);
    void print_wind (double[][col]);
    void format();
    
    int main()
    
    {
    	double windchillchart[row][col] = {0};
    
        windchill (windchillchart);
    	format();
    
        print_wind (windchillchart);
    
    	return 0;
    
    }
    
    
      void windchill (double n[][col])
    
      {
    	  
    	
         for (int i=0,t = 40;i<row;i++,t-=5 )
    		 for (int j=0, v = 5; j<col;j++, v += 5)
    		 {
    			n[i][j] = 35.75 + .6215*(t) - 35.75*(pow(v,0.16)) + .4275*(t)*(pow(v,0.16)); 
    
    
    		 }
    		
    
      }		
    		
    		
    		
    		
    		
    		
    void print_wind (double n[][col])
    
    {
    
    	int i,t,j,v;
    	cout << "\t\t    Wind Speed in MPH / Temperture in F \n\n";
        cout << "  ";
    
    	for (i=0, t=40;i<col;i++,t-=5)
         	cout << setw(4) << t;
            cout << "\n\n";
    	for (i=0,v=5;i<row;i++,v+=5)
     	{
    		cout << setw(2) << v;
    	for (j=0;j<col;j++)
    		cout << setw(4) << n[i][j];
    		cout << "\n";
    
    	}
    }
    
    void format()
    {
    	cout << setiosflags(ios::fixed);
    	cout << setprecision(0);
    }

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    14

    temp

    the temps should be 36 31 25 19 13 7 1 -5

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    14

    row col in array

    Ok the only problem i'm having now is getting the col rows correct
    the temps going across the rows should be going down the cols and the temps going down should be going across the rows

    could someone help me please. thanks

    never mind i got it figured out. thanks anyways
    Last edited by lizardking3; 09-22-2003 at 09:18 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with functions
    By saliya in forum C Programming
    Replies: 1
    Last Post: 11-05-2007, 10:36 PM
  2. Problem with system(), execl(), etc. functions
    By nickkrym in forum C Programming
    Replies: 5
    Last Post: 05-12-2007, 09:04 AM
  3. Problem: Functions
    By Dmitri in forum C Programming
    Replies: 21
    Last Post: 11-06-2005, 10:40 AM
  4. Problem with pointers and functions
    By Kheila in forum C++ Programming
    Replies: 5
    Last Post: 10-13-2005, 01:40 PM
  5. problem with functions and "parse errors"
    By bart in forum C++ Programming
    Replies: 3
    Last Post: 08-27-2001, 09:52 AM

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