Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
1.44/5 (3 votes)
See more:
12345+67890

How to input this line?

What I have tried:

I DON'T KNOW ANYTHING REGAARDING THIS..
Posted
Updated 13-Oct-18 6:34am
Comments
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.

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:
"12345"
"+"
"67890"
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.
 
Share this answer
 
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.
 
Share this answer
 
Quote:
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900