Making the Arduino a Calculator

Hello all,

I am trying to figure out how to make the arduino accept an equation from the user and spit out an answer with a given input. For example, I want the arduino to accept a user input of "2*x". Then, I will request what "x" do you want. I will say "2" for x = 2, and the arduino should spit out "4" as an answer. These functions can come in a variety of forms including sin, cos, exponentials.

Here is my code thus far. I am having trouble setting up how to read entire strings. Then my next problem is converting that string into a function the arduino can recognize.

Thank you for any help you can offer.

void setup() {
  Serial.begin(9600);

}

char p = ' ';
int junk = 0;
void loop() {

  int junk = 0;
  Serial.println(F("Gimme a function"));
   while (Serial.available() == 0); {  // Wait here until input buffer has a character
    p = Serial.read();
    while (Serial.available() > 0) {  // .parseFloat() can leave non-numeric characters
     junk = Serial.read() ;       // clear the keyboard buffer
    }
  }
Serial.println(p);
}

You need to store ALL of the characters until you get a line terminator, and don't throw any away like you are doing with junk.

This is a generic app that has been written many times (often given out as an intermediate programming exercise). A few months ago, I looked online and found lots of example programs.