Monday, May 24, 2010

I keep getting a undeclared identifier error? c++?

/***************************************...


*


* Program name: Lab 10


* Author : Daniel J. Carr


* Date : December 10th, 2007


* Course/selection: CSC-110-003


* Program Description:


*


*


*


**************************************...


/************************** Compiler Directives **********************/


// libraries


#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;cmath%26gt;





using namespace std;


/*********************** Global Data Declarations ********************/


/*************************** Function Prototype **********************/





void chop(float chipmunk,int%26amp; head,float%26amp; tail);





/*************************************...


*


* Function name: Main


* Author: Daniel J. Carr


* Date: December 10th, 2007


* Function Description:


*


* Pseudocode:


* Level 0


* -------


* Enter a float


* Chop it


* Output pieces


*


*


* Level 1


* -------


* Enter a float


* Display "Enter a floating point number----%26gt; "


* Input Chipmunk


* Chop it


* Call funtion chop to split chipmunk into head and tail


* Output Pieces


* Display "The whole number---%26gt; "%26amp; head %26amp; EOL


* Display "The Deciman number-%26gt; "%26amp; tail %26amp; EOL


*


**************************************...


int main()


{


//Varables


float chipmunk;


//arguements








void chop (int%26amp; head,float%26amp; tail);





cout %26lt;%26lt; "Enter a floating point number----%26gt; " %26lt;%26lt; endl;


cin %26gt;%26gt; chipmunk;





//Call function chop





cout %26lt;%26lt; "The whole number----%26gt; "%26lt;%26lt; head %26lt;%26lt; endl;


cout %26lt;%26lt; "The Decimal number--%26gt; "%26lt;%26lt; tail %26lt;%26lt; endl;








//Indicate successful termination of program





return 0;


}





//End main


/*************************************...


*


* Function name: Chop


* Author: Daniel J. Carr


* Date: December 4th


* Function Description:


*


* Pseudocode:


* Level 0


* -------


* Chop it


*


* Level 1


* -------


* Chop it


* whole = int(number)


* Decimal =|number-whole|


*


**************************************...





void chop(float chipmunk,int%26amp; head,float%26amp; tail)


{


// Variables





// Arguements


chipmunk = head;


tail = abs(chipmunk-head);








}

I keep getting a undeclared identifier error? c++?
In the future, if you get errors, please include the entire error text. It makes finding the problem much easier.





You declare chop twice with two different signatures:





void chop(float chipmunk,int%26amp; head,float%26amp; tail);


void chop (int%26amp; head,float%26amp; tail);





The first one globally and the second inside main(). In C++, you are allowed to have multiple versions of a function with different parameters, so this does not generate an error at first.





Later you implement only the first signature. If you call the shorter version of chop() in main(), you are calling the one that does not exist.





Remove the declaration of chop() in main()


void chop (int%26amp; head,float%26amp; tail);





Now, using only the global declaration everything should be OK. You may get a compiler error if your calling code did not match the declaration. This should be easy to fix.
Reply:hey Dan


this is the3 same script site i reffered earlier hope it did help you, checjk that again





Daniweb is my favorite, this guys know C/C++, I hope that helps you


\


good luck man
Reply:perhaps there is a variable you use in the code that you havent had pre-declared.


No comments:

Post a Comment