Answer the question
In order to leave comments, you need to log in
How to make a similar program in c++ (for those who know python and c++)?
Python code:
def divide(a, b):
return int(a) / int(b)
def fold(a, b):
return int(a) + int(b)
def multiple(a, b):
return int(a) * int(b)
def take(a, b):
return int(a) - int(b)
def main():
print('Введите выражение')
userInput = input()
while True:
userInput2 = userInput.split('/')
l = len(userInput2)
if l > 1:
result = divide(userInput2[0], userInput2[1])
print(result)
break
userInput2 = userInput.split('+')
l = len(userInput2)
if l > 1:
result = fold(userInput2[0], userInput2[1])
print(result)
break
userInput2 = userInput.split('*')
l = len(userInput2)
if l > 1:
result = multiple(userInput2[0], userInput2[1])
print(result)
break
userInput2 = userInput.split('-')
l = len(userInput2)
if l > 1:
result = take(userInput2[0], userInput2[1])
print(result)
break
main()
Answer the question
In order to leave comments, you need to log in
In fact, I know everything except .split, so I would like you to give an example of working with the .split analog in c ++
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question