Issues with prototype

I have written some code and I ask for it to be reviewed,(by a person I answer to)
They have said that my prototype is incorrectly written. Needs data type for formal parameter. I do not understand the incorrectness. Can you find and discuss why it is wrong. I also need this to floor or (round the output. I am still learning here be gentle... Thanks



#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

void instruct();
// prototype
float findRound(float value);

int main()

{
#define a 100

float (value);
float findRound(float value);

// Displays user instructions
instruct();

cout << " Enter a decimal number with a fractional part " <<endl;
cin >> value;

system ("cls");

cout << value << " rounded to 2 decimal places is " << value <<endl;


system("PAUSE");
return 0;
} // end main
// Displays user instructions
void instruct()

{
//User instructions
cout << "This program will round a decimal number with a fractional part " <<endl;
cout << "Please enter a postive deciaml number (example: 12.34567) " <<endl;
cout << "This program will return the rounded number " <<endl;

} //end instruct

// coumpute and round the value
float findRound(float value)
{
// Computes value and decinum to get rounding
return floor((value * a + 0.5) / a);

} //end findRound


I also tried to use the insert code tag but it does not seem to be
aas it should...?
Last edited on
please use code tags.

Nothing is wrong with your prototypes, that I see. Other than you putting a second prototype inside of main (you don't need to do that -- it's already prototyped above main)

1
2
3
4
5
6
7
8
9
float findRound(float value);   // okay! -- prototype

int main()

{
#define a 100    // blech @ #define, but whatever

float (value);   // very odd way to declare a variable.  Lose the parenthesis
float findRound(float value);  // get rid of this.  findRound is already prototyped above. 



EDIT

I just tried the code out -- and apparently you're never actually calling findRound. Is that what you meant to do with that second prototype? (also your rounding doesn't work right even if you call it)
Last edited on
Rounding Algorithms
http://www.cplusplus.com/forum/articles/3638/

For code tags, place it like

[code]
#include <iostream>
int main()
{
std::cout << "Hello world\n";
return 0;
}
[/code]

to obtain

1
2
3
4
5
6
#include <iostream>
int main()
  {
  std::cout << "Hello world\n";
  return 0;
  }


Hope this helps.
Last edited on
Duoas,

That what I needed to see to post properly. Thanks
Disch,
I just tried the code out -- and apparently you're never actually calling findRound. Is that what you meant to do with that second prototype? (also your rounding doesn't work right even if you call it)


This has been the issue with this project from its beging for me. I have not been able to get
this flooring op in my head the right way and where to put it so it works. Thanks for helping
Trying the code tag, hey it works if you know how to paste between the blocks. Cool Now a little more help would be great. I need this function to floor the output properly. Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include  <cmath>
#include <cstdio>
using namespace std;

	void instruct();

	// prototype
	float findRound(float value);

int main()

{
#define a 100
    
    float value;
	float findRound;

    // Displays user instructions
    instruct();	
    
    cout << " Enter a decimal number with a fractional part " <<endl;
    cin >> value;
    
    system ("cls");
    				
		cout << value << " rounded to 2 decimal places is " << value <<endl;
		
		
    
    system("PAUSE");
    return 0;
}   // end main
// Displays user instructions
void instruct()

{
    //User instructions
    cout << "This program will round a decimal number with a fractional part " <<endl;
    cout << "Please enter a postive deciaml number (example: 12.34567) " <<endl;
    cout << "This program will return the rounded number " <<endl;
        
} //end instruct

// coumpute and round the value
float findRound(float value)
{
      // Computes value and decinum to get rounding
      return (floor(value * a + 0.5) / a);      
      
} //end findRound 
Last edited on
Ok I have attempted to correct the issues myself, but I am still not being sucessful at my attempts. This project has been turned in and I am attempting to get it to work properly so that I may learn the proper method of "floor". It was in February when I put this code together. Now it is coming close to finals and I need to get this "floor" issue and how to do it properly in my head. I thank each of you for your efforts in growing me.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include  <cmath>
#include <cstdio>
using namespace std;

	void instruct();

	// prototype
	float findRound(float value);

int main()

{
#define a 100
    
    float value;
	float findRound(float value);

    // Displays user instructions
    instruct();	
    
    cout << " Enter a decimal number with a fractional part " <<endl;
    cin >> value;
    
    system ("cls");
    				
		cout << value << " rounded to 2 decimal places is " << value <<endl;
		
		    
    system("PAUSE");
    return 0;
}   // end main
// Displays user instructions
void instruct()

{
    //User instructions
    cout << "This program will round a decimal number with a fractional part " <<endl;
    cout << "Please enter a postive deciaml number (example: 12.34567) " <<endl;
    cout << "This program will return the rounded number " <<endl;
        
} //end instruct

// coumpute and round the value
float findRound(float value)
{
      // Computes value and decinum to get rounding
      return ((value * a + 0.5) / a)(floor);      
      
} //end findRound 


1
2
3
4
1>G684L2P2.cpp
1>c:\users\owner\documents\visual studio 2008\projects\g684l2p2\g684l2p2\g684l2p2.cpp(62) : error C2064: term does not evaluate to a function taking 1 arguments
1>Build log was saved at "file://c:\Users\owner\Documents\Visual Studio 2008\Projects\G684L2P2\G684L2P2\Debug\BuildLog.htm"
1>G684L2P2 - 1 error(s), 0 warning(s)
"Disch", "Duoas" Please expound on this lesson I need to learn how to use floor, properly. You both seem to have what I need.
Topic archived. No new replies allowed.