/***************************************...
*
* 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
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);
}
Ok last time im going to try this. Im coming up with a undeclared identifier error in main. this is c++?
//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;
Two problems
1) Main never calls the function chop (logic problem)
call chop(chipmunk,headmain,tailmain)
from the main program and declare variables headmain and tailmain in the main function. Also set headmain = 1 and tailmain = 1.f to avoid the variable is used without being set error.
2) In
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;
you try to use the variables declared ONLY inside the chop function in the main program (ONLY within the chop function can the head and tail variables be used)
Just move these statements inside the chop function (IE at the end of it) and they should work :-)
Reply:"head" and "tail" are never declared in main(). You attempt to set them, but they don't have a type associated with them or anything.
Also in chop() you are setting chipmunk, not head.
Reply:You are trying to reference 2 varibles that have not been declared.
Make it look like this...
//Varables
float chipmunk;
int head;
float tail;
Also, since 'abs' returns a double you should use the 'fabs' function instead.
2nd post:
Thats because you declared them, but not yet used them.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment