double operations

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 3 Exercise 5
Using std_lib_facilities.h by Bjarne Stroustrup.

//	Philipp Siedler
//	Bjarne Stroustrup's PP
//	Chapter 3 Exercise 5

#include "std_lib_facilities.h"

int main()
{
	double val1, val2;
	cout << "enter one float value ";
	cin >> val1;
	cout << "enter another float value ";
	cin >> val2;
	cout << val1 << ", " << val2 << "\n";

	if (val1 < val2)
		cout << "val1 " << val1 << " is smaller than val2 " << val2 << "\n";
	else
		cout << "val1 " << val1 << " is larger than val2 " << val2 << "\n";

	cout << "the sum of val1 and val2 is " << val1 + val2 << "\n";
	cout << "the difference of val1 minus val2 is " << val1 - val2 << "\n";
	cout << "the product of val1 and val2 is " << val1 * val2 << "\n";
	cout << "the ratio of val1 to val2 is " << val1 / val2 << "\n";

	keep_window_open();
}
Output:
enter one float value 1 2
enter another float value 1, 2
val1 1 is smaller than val2 2
the sum of val1 and val2 is 3
the difference of val1 minus val2 is -1
the product of val1 and val2 is 2
the ratio of val1 to val2 is 0.5
Please enter a character to exit

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.