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);
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.
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>
usingnamespace 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!!!