Monday, May 24, 2010

What am I doing wrong here in my 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;


int head;


float tail;











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


cin %26gt;%26gt; chipmunk;








//Call function chop





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


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








}

What am I doing wrong here in my c++ ?
I haven't studied this too carefully, but this line doesn't do what you think it does:





//Call function chop





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





You're not calling the function that you declare later in the file. You should call it this way:





chop(chipmunk, head, tail);





Also your chop function doesn't do what you think it does. You're assigning head to chipmunk but there's nothing in head when it is called.

garden centre

No comments:

Post a Comment