integer operations

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

[code language=”cpp”]
// Philipp Siedler
// Bjarne Stroustrup’s PP
// Chapter 3 Exercise 4

#include "std_lib_facilities.h"

int main()
{
int val1, val2;
cout << "enter one integer value ";
cin >> val1;
cout << "enter another integer 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();
}
[/code]

Output:
enter one integer value 2
enter another integer value 3
2, 3
val1 2 is smaller than val2 3
the sum of val1 and val2 is 5
the difference of val1 minus val2 is -1
the product of val1 and val2 is 6
the ratio of val1 to val2 is 0
Please enter a character to exit

Leave a Reply