Re: Project 2
Huh, I can be wrong, but noone used ?: operator 
and some example of output:
- Code: Select all
// Proj2_Stat.cpp: Another 5 cents for this project solution...
// Best regards, AntidotE.
// Needed remark: "I... personally believe, thaaat..." (c) ;) 0 is non-positive and non-negative.
#include <iostream>
#include <cmath> //for using abs
using namespace std;
int main()
{
int n1, n2;
char ask = 'y';
cout << "Hello, this is Project2 solution hereinafter named 'Stat'..." << endl << endl;
cout << " First of all, Stat'd like to note, that here is NO defence from fools :(" << endl;
cout << " That's why you have to be precisely sure what you are typing." << endl;
do
{
cout << endl;
cout << "Stat asks for FIRST number => ";
cin >> n1;
cout << "Stat asks for SECOND number => ";
cin >> n2;
cout << endl << "Stat answers: " << endl;
cout << n1 << " and " << n2 << " are" << ( ( n1 != n2 ) ? " not " : " " ) << "equal!" << endl;
cout << ( ( n1 > n2 ) ? n1 : n2 ) << " is > than " << ( ( n1 > n2 ) ? n2 : n1 ) << endl;
cout << ( ( n1 < n2 ) ? n1 : n2 ) << " is < than " << ( ( n1 < n2 ) ? n2 : n1 ) << endl;
cout << n1 << " is" << ( ( n1 >= n2 ) ? " " : " not " ) << ">= than " << n2 << endl;
cout << n1 << " is" << ( ( n1 <= n2 ) ? " " : " not " ) << "<= than " << n2 << endl;
cout << n1 << " is " << ( ( n1 % 2 ) ? "odd" : "even" ) << endl;
cout << n2 << " is " << ( ( n2 % 2 ) ? "odd" : "even" ) << endl;
cout << n1 << " is " << ( ( n1 > 0 ) ? "positive" : ( ( n1 < 0 ) ? "negative" : "zero" ) ) << endl;
cout << n2 << " is " << ( ( n2 > 0 ) ? "positive" : ( ( n2 < 0 ) ? "negative" : "zero" ) ) << endl;
cout << "difference between " << n1 << " and " << n2 << " is " << abs( ( n1 > n2 ) ? ( n2 - n1 ) : ( n1 - n2) ) << endl;
cout << n1 << " / " << n2 << " = " << (double)( (double)n1 / (double)n2 ) << endl;
cout << n2 << " / " << n1 << " = " << (double)( (double)n2 / (double)n1 ) << endl;
cout << endl;
cout << "Stat asks: 'Would you like to try one more time?'" << endl;
cout << " ('y' is yes, everything else is no) => ";
cin >> ask;
} while ( ask == 'y' );
return 0;
}
and some example of output:
- Code: Select all
Hello, this is Project2 solution hereinafter named 'Stat'...
First of all, Stat'd like to note, that here is NO defence from fools :(
That's why you have to be precisely sure what you are typing.
Stat asks for FIRST number => 5
Stat asks for SECOND number => -8
Stat answers:
5 and -8 are not equal!
5 is > than -8
-8 is < than 5
5 is >= than -8
5 is not <= than -8
5 is odd
-8 is even
5 is positive
-8 is negative
difference between 5 and -8 is 13
5 / -8 = -0.625
-8 / 5 = -1.6
Stat asks: 'Would you like to try one more time?'
('y' is yes, everything else is no) =>