Permalink
Browse files

Lesson_5

  • Loading branch information...
1 parent 54f3f60 commit b272b69573bf8ef530ec77f2c9fc5932132e33be Vis Viva committed Apr 20, 2012
Showing with 102 additions and 0 deletions.
  1. +102 −0 Lesson_5
View
102 Lesson_5
@@ -0,0 +1,102 @@
+#include <iostream>
+
+int main()
+{
+ char chOperation;
+ double dsFirstNumber(0.0), dsSecondNumber(0.0);
+
+STRTPRG: chOperation = '0'; // ������������� �������� ��������
+
+ std::cout << "|--------------------------------------|";
+ std::cout << "\n| Choose ";
+ std::cout << "\n|--------------------------------------|";
+ std::cout << "\n| 0 for + ";
+ std::cout << "\n| 1 for - ";
+ std::cout << "\n| 2 for * ";
+ std::cout << "\n| 3 for / ";
+ std::cout << "\n| 4 for % ";
+ std::cout << "\n|--------------------------------------|";
+ std::cout << "\n| Your choice: ";
+
+ std::cin >> chOperation;
+
+ if (!((chOperation >= '0') && (chOperation <= '4'))) // ������ �������� �� ����������� ������ �� ASCII �������
+ {
+ std::cout << "|\n| Please, make a decent choice!\n";
+ goto STRTPRG;
+ }
+
+ std::cout << "|\n| First number: ";
+ std::cin >> dsFirstNumber;
+
+ std::cout << "|\n| Second number: ";
+ std::cin >> dsSecondNumber;
+ std::cout << "|--------------------------------------|";
+ std::cout << "\n| ";
+
+ switch (chOperation) // ������ �������� �� ��� ��������
+ {
+ case '0':
+ {
+ std::cout << dsFirstNumber << " + " << dsSecondNumber << " = " << dsFirstNumber + dsSecondNumber;
+ break;
+ }
+
+ case '1':
+ {
+ std::cout << dsFirstNumber << " - " << dsSecondNumber << " = " << dsFirstNumber - dsSecondNumber;
+ break;
+ }
+
+ case '2':
+ {
+ std::cout << dsFirstNumber << " * " << dsSecondNumber << " = " << dsFirstNumber * dsSecondNumber;
+ break;
+ }
+
+ case '3':
+ {
+ std::cout << dsFirstNumber << " / " << dsSecondNumber << " = " << dsFirstNumber / dsSecondNumber;
+ break;
+ }
+
+ case '4':
+ {
+ std::cout << "Only integers are allowed!"; // ��������� ������ ����� �����!
+ std::cout << "\n| Forced casting will be applied."; // �������� ������������� ������� �������
+ std::cout << "\n| ";
+ std::cout << "\n| ";
+ std::cout << static_cast<int>(dsFirstNumber) << " % " << static_cast<int>(dsSecondNumber) << " = " << static_cast<int>(dsFirstNumber) % static_cast<int>(dsSecondNumber);
+ break;
+ }
+ }
+
+YESORNO: chOperation = '0'; // ������������� ��������� ��� ������ �� ���������
+
+ std::cout << "\n|--------------------------------------|";
+ std::cout << "\n| Again? ";
+ std::cout << "\n|--------------------------------------|";
+ std::cout << "\n| 0 for No ";
+ std::cout << "\n| 1 for Yes ";
+ std::cout << "\n|--------------------------------------|";
+
+ std::cout << "\n| Your choice: ";
+ std::cin >> chOperation;
+
+ switch (chOperation) // ������ �������� �� ��� ��������
+ {
+ case '1':
+ goto STRTPRG; // ������������� �������� ��������
+
+ case '0':
+ break;
+
+ default:
+ std::cout << "|\n| Please, say Yes or No!";
+ goto YESORNO; // ������������� ��������� ��� ������ �� ���������
+ }
+
+ std::cout << "|--------------------------------------|\n\n";
+
+ return 0;
+}

0 comments on commit b272b69

Please sign in to comment.