update demo flie l5.cpp, add new function polz for request numbers and sign
This commit is contained in:
parent
fa79441e47
commit
03bc2b79bb
1 changed files with 25 additions and 8 deletions
31
c++/l5.cpp
31
c++/l5.cpp
|
|
@ -1,9 +1,8 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
int main() {
|
int polz(void) {
|
||||||
int s = 0;
|
while(1) {
|
||||||
while(s <= 3) {
|
|
||||||
std::string pol;
|
std::string pol;
|
||||||
std::cout << "Знак" << std::endl;
|
std::cout << "Знак" << std::endl;
|
||||||
std::cin >> pol;
|
std::cin >> pol;
|
||||||
|
|
@ -15,24 +14,42 @@ int main() {
|
||||||
std::cin >> x2;
|
std::cin >> x2;
|
||||||
if(pol == "+") {
|
if(pol == "+") {
|
||||||
std::cout << x1 << pol << x2 << "=" << x1+x2 << std::endl;
|
std::cout << x1 << pol << x2 << "=" << x1+x2 << std::endl;
|
||||||
s++;
|
|
||||||
}
|
}
|
||||||
else if(pol == "-") {
|
else if(pol == "-") {
|
||||||
std::cout << x1 << pol << x2 << "=" << x1-x2 << std::endl;
|
std::cout << x1 << pol << x2 << "=" << x1-x2 << std::endl;
|
||||||
s++;
|
}
|
||||||
|
else if(pol == "exit") {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if(pol == "*") {
|
else if(pol == "*") {
|
||||||
std::cout << x1 << pol << x2 << "=" << x1*x2 << std::endl;
|
std::cout << x1 << pol << x2 << "=" << x1*x2 << std::endl;
|
||||||
s++;
|
|
||||||
}
|
}
|
||||||
else if(pol == "/") {
|
else if(pol == "/") {
|
||||||
std::cout << x1 << pol << x2 << "=" << x1/x2 << std::endl;
|
std::cout << x1 << pol << x2 << "=" << x1/x2 << std::endl;
|
||||||
s++;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::cout << "Неверный знак" << std::endl;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
std::cout << "Введите верное число" << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue