M
M
Maxim Siomin2020-07-04 21:34:09
Python
Maxim Siomin, 2020-07-04 21:34:09

How to make a similar program in c++ (for those who know python and c++)?

Python code:

spoiler
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()

In fact, I know everything except .split, so I would like you to give an example of working with the .split analog in c ++

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-07-04
@sergey-gornostaev

In fact, I know everything except .split, so I would like you to give an example of working with the .split analog in c ++

Have you tried google "c++ split string"?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question