Click here to Skip to main content
13,863,034 members
Rate this:
Please Sign up or sign in to vote.
See more:

How to input this line?

What I have tried:

Updated 13-Oct-18 7:34am
Afzaal Ahmad Zeeshan 13-Oct-18 12:57pm
That is not going to be input by a number variable, read a string (character array if not using a string type), then read the characters one by one and start to process them.

You can also process them in-flight, read the character and process it.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Read it as a string, then - assuming it won't always have a "+" in the middle - process it into a collection of strings: a sequence of numerics becomes a string, a sequence of non-numerics becomes another.
In this case you will end up with three strings:
You can then convert the numerics to numbers, and work out the expression using a switch statement.

It's not difficult if you do it stage by stage - but this is your homework, not mine, so I'll give you no code!
Sit down and think about it for a few minutes - it's really not as complicated as you seem to think.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

For your homework you need to learn from some C++ tutorial.

Especially you need to learn the usful functions of std::string like spliting and adding characters.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

How to input this line?

Exactly like any other arbitrary string of chars, input as a string.
And after you process the string to get the result you want.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web05 | 2.8.190214.1 | Last Updated 13 Oct 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100