浏览代码

add new demo file calculator c++/l5.cpp

root 1 月之前
父节点
当前提交
fa79441e47
共有 1 个文件被更改,包括 38 次插入0 次删除
  1. 38 0
      c++/l5.cpp

+ 38 - 0
c++/l5.cpp

@@ -0,0 +1,38 @@
+#include <iostream>
+#include <string>
+
+int main() {
+	int s = 0;
+	while(s <= 3) {
+		std::string pol;
+		std::cout << "Знак" << std::endl;
+		std::cin >> pol;
+		double x1;
+		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 == "*") {
+			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;
+			return 0;
+		}
+	}
+	return 0;
+}