macho_rounding

macho_rounding - /from cmath or math.h which must...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 // class 3 demo 3 #include <iostream> #include <cmath> using namespace std int main() { double num = 0.0 double roundedNum = 0.0 cout << "Enter a number with more than 2 decimal places: " cin >> num roundedNum = (int ((num * 100) + 0.5))/ 100.0 // or // roundedNum = (int ((num * 100) + 0.5))/ 100.0 // or // roundedNum = (floor ((num * 100) + 0.5))/ 100.0
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //from cmath or math.h which must be //included at the top of the program cout << num << " rounded to the nearest hundredth's is " << roundedNum << endl return 0 } //end of main Sheet1 Page 2 using old-fashioned type casting using the floor library function u...
View Full Document

This note was uploaded on 04/01/2008 for the course CMPSC 101 taught by Professor Drobish,renee during the Spring '07 term at Penn State.

Page1 / 2

macho_rounding - /from cmath or math.h which must...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online