Click here to Skip to main content
13,795,074 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
12345+67890

How to input this line?

What I have tried:

I DON'T KNOW ANYTHING REGAARDING THIS..
Posted 13-Oct-18 5:50am
Updated 13-Oct-18 7: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.
Rate this: bad
 
good
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:
"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.
  Permalink  
Rate this: bad
 
good
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.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  

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
Web02 | 2.8.181207.3 | Last Updated 13 Oct 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

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