What is wrong with my calculator? :)

Hi there. I'm pretty new to C++ and need some help. I'm attempting to create a calculator but I get 12 errors when I compile it. So could anyone tell me what's wrong with this?


This is what my compiler tell me is wrong. input is a string.

1
2
3
4
5
for (int i = 0; i =< input.size(); i++)
{
	if ((input[i] == "+") || (input[i] == "-") || (input[i] == "*") || (input[i] == "/"))
		arithmeticOperators += 1;
}
What are the errors? Anyway, you are comparing input[i] (a char) to "+" (a string) etc. I think you mean '+' (a char), notice the single 's.
The first thing I see is a problem with the bigger than or equal to operator. It should be <= instead of =<.
As firedraco said, replace the quotation marks for single quotes.
I don't know if you declare the array, so you need to display the whole code and the error report.
He said it was a string, so there aren't any problems there. Also, the <= should be just <, the array goes from 0 - (size()-1)
Thanks for the answers, it works now :)

I just had to change every " to ' and =< to <.

But could someone explain the difference between " and '?
I thought they were the same.
" are for character sequences, eg: "hello world"
' are used for single character, eg: 'A'.
You can use single quotes for multi-character constants but this is useless: int i = 'wtf?';
Thank you Bazzy :)
Topic archived. No new replies allowed.