Sfoglia il codice sorgente

update demo flie l5.cpp, add new function polz for request numbers and sign

root 1 mese fa
parent
commit
03bc2b79bb
1 ha cambiato i file con 25 aggiunte e 8 eliminazioni
  1. 25 8
      c++/l5.cpp

+ 25 - 8
c++/l5.cpp

@@ -1,38 +1,55 @@
 #include <iostream>
 #include <string>
 
-int main() {
-	int s = 0;
-	while(s <= 3) {
+int polz(void) {
+	while(1) {
 		std::string pol;
 		std::cout << "Знак" << std::endl;
 		std::cin >> pol;
 		double x1;
-		std::cout << "Первое число" << std::endl;
+    	std::cout << "Первое число" << std::endl;
 		std::cin >> x1;
 		double x2;
 		std::cout << "Второе число" << std::endl;
 		std::cin >> x2;
 		if(pol == "+") {
 			std::cout << x1 << pol << x2 << "=" << x1+x2 << std::endl;
-			s++;
 		}
 		else if(pol == "-") {
 			std::cout << x1 << pol << x2 << "=" << x1-x2 << std::endl;
-			s++;
+		}
+		else if(pol == "exit") {
+			break;
 		}
 		else if(pol == "*") {
 			std::cout << x1 << pol << x2 << "=" << x1*x2 << std::endl;
-			s++;
 		}
 		else if(pol == "/") {
 			std::cout << x1 << pol << x2 << "=" << x1/x2 << std::endl;
-			s++;
 		}
 		else {
 			std::cout << "Неверный знак" << std::endl;
+			break;
+		}
+	}
+	return 1;	
+}
+
+int main() {
+	while(1) {
+		std::cout << "1. Начать\n2. Закончить" << std::endl;
+		int pol1;
+		std::cout << "Введите число" << std::endl;
+		std::cin >> pol1;
+		if(pol1 == 1) {
+			polz();
+		}
+		else if(pol1 == 2) {
 			return 0;
 		}
+		else {
+			std::cout << "Введите верное число" << std::endl;
+		}
 	}
 	return 0;
 }