I can't see the forrest

I have worked on this weeks, it still will not round the results.
Any suggestions?

Program Description: Program will recieve from the user a positive decimal
number. It will then compute the input and round the input.

Program Design:
input: a decimal number with a fractional part
compute the input and round the number.
*/

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

void instruct();

int main()

{
#define a 100

float (value);
// prototype
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 don't see where you're calling the findRound function. I see you prototyped it and defined it but in your cout statement you print value and value. Now I'm pretty novice but I would think to make use of that function you'd have to have called it somewhere in there... that is unless I missed it.

:o)
D
You also haven't initialized the 'value' vairable.
I thank you for your efforts i think I have it now

MDG
Hmm weeks and not working? Well use this bit of info to ur advantage. Integers truncate if a decimal is entered and to prove it I wrote this code quickly
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;

int decimalNumber = 0;


int main() {
	
cout << "Input a decimal number please.";
cin >> decimalNumber;
cout << "The decimal number you entered was rounded to:" << decimalNumber;

return 0;

}


There is a bug which is it will not round up even if the unit after the decimal place is greater than 5 and will round down instead so you can work round that by using a if statement( or algorithim?) to determine if the unit after the decimal place is over 5 if so add one to the final result as the integer round down!!!

Hope that helps

Arcadiu



Last edited on
Topic archived. No new replies allowed.