I am writing a program for class which takes an expression as input and then prints out the numbers in the expression and the symbols from the expression in order. So for example:
Input:
(5 * 30) + 4
What output should be:
5 30 4 ( * ) +
My output is:
5 3 0 4 ( * ) +
So I have everything figured out except how I should be keeping multiple digit numbers together. Any advice would be greatly appreciated!
#include <vector>
#include <string>
#include <iostream>
#include<cctype>
usingnamespace std;
int main()
{
string userIn;
vector<char> numbers;
vector<char> symbols;
cout << "Enter an expression: ";
getline(cin, userIn);
//Adding each single user input char to a vector
vector<char> inputVector(userIn.begin(), userIn.end());
//Dividing characters by number or symbol and placing them into two separate vectors
for (unsignedint i = 0; i < inputVector.size(); i++) {
if (isdigit(inputVector[i])) {
numbers.push_back(inputVector[i]);
} else {
if (!isspace(inputVector[i])) {
symbols.push_back(inputVector[i]);
}
}
}
//Printing characters in number vector
for (unsignedint i = 0; i < numbers.size(); i++) {
cout << numbers[i] << " ";
}
//Printing elements in symbols vector
for (unsignedint i = 0; i < numbers.size(); i++) {
cout << symbols[i] << " ";
}
cout << endl;
return 0;
}