0

Hi guys...

I've downloadws today the IronPython. One thing i've noticed that if you type, for example, 5+6 it calculates it..!

So, i tried to do that with my App too, without success...

Note: I've tried "if" sentences, but they are pretty useless...

Help!

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by _adam_
0

Um, what? It sounds like you want to write an interpreter, but your question was so freaking vague I can't be sure. :icon_rolleyes:

0

I've downloadws today the IronPython. One thing i've noticed that if you type, for example, 5+6 it calculates it..!

So, i tried to do that with my App too, without success...

You should be able to get this going with std::cin.

Here's a quick example:

#include <iostream>

int main()
{
	int number1, number2;
	char mathsOperator;

	std::cout << "Enter a sum. (E.g. '1 + 3')" << "\n";
	std::cin >> number1;
	std::cin >> mathsOperator;
	std::cin >> number2;

	std::cout << "\n";

	switch( mathsOperator )
	{
	case '+':
		std::cout << "The Answer Is: " << number1 + number2 << "!\n\n";
		break;
	default:
		std::cout << "Invalid Operator!\n\n";
		break;
	};
}

I'll let you add the other operators. :)

All the best,
Adam

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.