:rolleyes: Hi. I'm new to this forum and well I'm also new to the programming languages. :) and im taking some programming classes c++) i need help with a program that im working on... I have tried for about two days to see what is the problem but i just dont get it. May be some one over can help me. Thanks

/*       straightlinedepr.cpp    */

#include <iostream>    // student ...... xXXXX
#include <cmath>       // assignment ... straight line depreciation
#include <cstdlib>     // due date .....10/13/2005
#include <iomanip>     //

using    namespace std;                // name-conflict avoidance

void     SetPrecision(int);            // procdedure prototype

int      main      (void)              // main function header
{
         /* local data space */
         double    cost, scrap;        // declare input values
         int       years;              //
         double CalcDepr ( double, double, int);
         double    yrlyDepr,cumDepr,bookVal; // declare derived
         int       year;                     // loop control var

         /* begin procedural code */
         SetPrecision(2);              // set float precision

         /* get input values */
         cout<< "Enter the cost: ";  //prompt
         cin>> cost;
         cout<< "Enter scrap value: "; //prompt
         cin>> scrap;
         cout<< "Enter lfe in years: ";
         cin>> years;



         /* display column headers */
         cout << setw(6)  << "Year"
              << setw(13) << "Yearly Depr"
              << setw(10) << "Cum Depr"
              << setw(12) << "Book Value" << "\n\n";

         /* pre-loop value calculations */
         yrlyDepr = CalcDepr(cost, scrap, years);     // call function
        double CalcDepr( double p_cost, double p_scrap, int p_years);

        {
                double depr;


                        depr= (p_cost - p_scrap)/ (float) p_years;
                return(depr);
         }
        cumDepr= 0;
        bookVal= cost;
        for ( year=1; year<=8;year++)
        {
                cumDepr=cumDepr +yrlyDepr;
                bookVal= bookVal-yrlyDepr;
        /*display detail line */
        cout<< setw(6)<<year<<setw (13)<< yrlyDepr<< setw(10)<<cumDepr<< setw(12
)<<bookVal<< endl;
        }



         /* develop repetiiton schedule */




         return(0);                    // int return to o/s
}

void     SetPrecision(int p_decPlaces) // procedure header
{                                      // begin block
         cout.setf(ios::fixed);
         cout.setf(ios::showpoint);
         cout.setf(ios::right);
         cout.precision(p_decPlaces);
         return;                       // return to caller
}                                      // end block
-bash-3.00$ aCC -AA straightlinedepr.cpp -o straightlinedepr
Error 172: "straightlinedepr.cpp", line 48 # Undeclared variable 'p_cost'.
                            depr= (p_cost - p_scrap)/ (float) p_years;
                                   ^^^^^^
-bash-3.00$

That's a subtle error telling you that functions don't nest in C++. But aside from that, your use of whitespace is painfully inconsistent, and you have too many pointless comments. Here is your code corrected, cleaned up, and reorganized to be more transparent, though I haven't run it:

// student ...... xXXXX
// assignment ... straight line depreciation
// due date .....10/13/2005
//
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>

using namespace std;

void SetPrecision ( int );
double CalcDepr ( double, double, int );

int main ( void )
{
  double cost, scrap;
  int years;
  double yrlyDepr, cumDepr, bookVal;
  int year;

  SetPrecision(2); // set float precision

  /* get input values */
  cout<< "Enter the cost: ";
  cin>> cost;
  cout<< "Enter scrap value: ";
  cin>> scrap;
  cout<< "Enter lfe in years: ";
  cin>> years;

  /* display column headers */
  cout << setw(6)  << "Year"
    << setw(13) << "Yearly Depr"
    << setw(10) << "Cum Depr"
    << setw(12) << "Book Value" << "\n\n";

  yrlyDepr = CalcDepr(cost, scrap, years);
  cumDepr = 0;
  bookVal = cost;

  for ( year = 1; year <= 8; year++ )
  {
    cumDepr = cumDepr + yrlyDepr;
    bookVal = bookVal - yrlyDepr;

    /*display detail line */
    cout<< setw(6)<< year
      << setw(13) << yrlyDepr
      << setw(10) << cumDepr
      << setw(12) << bookVal <<endl;
  }

  return(0);
}

void SetPrecision ( int p_decPlaces )
{
  cout.setf(ios::fixed);
  cout.setf(ios::showpoint);
  cout.setf(ios::right);
  cout.precision(p_decPlaces);
}

double CalcDepr ( double p_cost, double p_scrap, int p_years )
{
  double depr;

  depr = (p_cost - p_scrap) / p_years;

  return(depr);
}

you are attempting to declare a function CalcDepr() within another function main(). You can't to that. Move all the code for CalcDepr() outside function main() and it will probably compile ok, unless of course there are other errors.

[edit]Nevermind -- Narue answered your question. Too bad we can't delete our own posts like I can on other boards :cry:

thanks Naure, this really works :D and thanks for you tips i think all my mess was obstructing in my way to detect the problem :) from now on i will try to be more clean :lol:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.