calculator help?

hi there,

i'm trying to write a calculator. the user will enter the terms and they will be stored in arrays. i will be storing those terms in string arrays and then later turn them to double to work with them. but the user should be able to enter terms like sin(252) and the program should be able to recognize it and calculate it. but i haven't figured out a way to do it yet. any help please?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;

int main() {
	std::string input = "";
	getline( std::cin, input );
	char in [20];
	int numRead = 0;
	switch ( sscanf( input.c_str(), "%[a-zA-Z](%d)", in, &numRead ) ) {
		case 2:
			std::cout << "You are trying to find the " << in << " of " << numRead << std::endl;
		default:
			break;
	}
}


sin(34)
You are trying to find the sin of 34

Just like that...
Is that regex? With scanf?

Does that actually work?
The %[...] format specifier works similar to regex [...] for specifying ranges of and specific characters that can be matched, yes.
Yea I was surprised that it actually worked. The text editor I was using was even marking it in bold red as if to say it was errorneous, but when I compiled...no warnings
Topic archived. No new replies allowed.