Website Summary Files Commits Branches @commit @diff @stats
path: root / pract_SI / pract. 02 / task7.cpp
blob: 3c22a830ca8e0d0df54ee73f7834122c15a23722 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<iostream>
using namespace std;
int main()
{
	 // you can use int as well, but do you really need something as big as int?
	 short number;
	 unsigned char digit1, digit2, digit3, digit4, number1, number2;

	 cout << "Enter a 4-digit number: ";
	 cin >> number;

	 if (number < 1000 || number > 10000)
	 {
		  cout << "The input must be a 4-digit number!\n";
		  return 1;
	 }

	 digit1 = number / 1000;
	 digit2 = number / 100 % 10;
	 digit3 = number / 10 % 10;
	 digit4 = number % 10;

	 number1 = digit1 * 10 + digit4;
	 number2 = digit2 * 10 + digit3;

	 if (number1 < number2)
	 {
		  cout << "less (" << (int)number1 << " < " << (int)number2 << ")\n";
	 }
	 else
	 {
		  if (number1 == number2)
		  {
				cout << "equal (" << (int)number1 << " = " << (int)number2 << ")\n";
		  }
		  else
		  {
				cout << "greater (" << (int)number1 << " > " << (int)number2 << ")\n";
		  }
	 }


	 return 0;
}