simple calculator

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

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

#include "std_lib_facilities.h"

int main() {
	
	double value1 = 0.0;
	double value2 = 0.0;
	char operat = ' ';

	cout << "Please enter two double values and an operator in a row with space in between.\n";

	while (cin >> value1 >> value2 >> operat)
	{
		if (operat == '+')
		{
			cout << value1 << " " << operat << " " << value2 << " equals to: " << value1 + value2 << "\n";
		}
		if (operat == '-')
		{
			cout << value1 << " " << operat << " " << value2 << " equals to: " << value1 - value2 << "\n";
		}
		if (operat == '/')
		{
			cout << value1 << " " << operat << " " << value2 << " equals to: " << value1 / value2 << "\n";
		}
		if (operat == '*')
		{
			cout << value1 << " " << operat << " " << value2 << " equals to: " << value1 * value2 << "\n";
		}
	}
	return 0;

	keep_window_open("-");
}
Output:
Please enter two double values and an operator in a row with space in between.
6.3 8.9 *
6.3 * 8.9 equals to: 56.07

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.