I would first like to note that I am simply going by the most recent code you've posted.
Currently, answer is not defined, which is one of the issues. This can easily be changed by simply adding
int answer;
somewhere at the beginning of the main() function scope.
The second issue is that you can't simply push.back() stuff like +, -, /, *, or anything to that effect. Think of these as reserved words. There are multiple ways to fix this.
If you are absolutely adiment to use an int vector, you can simply push_back() the char version. Like so:
1 2 3 4
|
symbol.push_back( '-' );
symbol.push_back( '+' );
symbol.push_back( '/' );
symbol.push_back( '*' );
|
Most, if not all, C++ compilers will automatically convert the character to it's ASCII equivalent. You can see a full table of ASCII here:
http://www.asciitable.com/
I would recommend bookmarking that website. It includes the Extended ASCII characters, and there is a button on the top where you can see the Unicode table.
NOTE: You could also simply use the char datatype for the vector instead of having to deal with using the decimals.
For instance, if you were to just run this after:
std::cout << symbol[0];
and the symbol that was chosen was '+' then it would print out the integer 43 (it casts it to 43 because you put a char value into an int variable).
However, you would still need to re-translate that back into a usable symbol. Because of that, it would be much easier if you didn't use vectors at all for this case. I simply included the previous example in case the use of vectors was part of your assignment.
Since this is a homework assignment, I won't just give you the code, but I will give you some helpful advice on at least what I would do if I needed to use a random symbol.
> Have a 3rd random number.
> Use an If Statement to check what number that is equivalent to.
> Each If Statement would do the appropriate math and print out the results.
OR
> Also have a char value.
> Within the If Statement, set the char value to the appropriate symbol.
> Use std::cout at the end like you currently have it.
EDIT:
I forgot to mention
why you were getting that error. It was "expecting an expression" around the symbols. This is basically what the compiler was seeing:
symbol.push_back( NULL + NULL );
C++ Compilers do not like to calculate NULL values.
NOTE:
Though it is fairly unimportant in today's time of the memory difference (especially with such a tiny program), using an int variable for something that would never have a number higher than 100 stored in it is a waste of space.
The int datatype uses 32 bits, while the short uses 16.
The int datatype can hold a little over 4 billion numbers (around negative 2B to positive 2B, or 0 to a little over 4B unsigned).
The short only uses about 65k numbers.
HOWEVER: You should only ever really need to worry about such a big difference if you are a part of a team that is making a VERY extensive program, or if you just want to make a program as efficient as possible. At your level though, I would just worry about getting the code to work. I just thought it would be a good idea to mention this early in your learning process.