i want to make a smal program that evaluate a math expresion like "3*14+25-5"...and i realy dont know what i do wrong...

my idea is to put evrything in a array of strings... so it will look like this:
myvect[0]=3
myvect[1]=*
myvect[2]=14
myvect[3]=+
......
and after i check the priority of the operators using the "grad(int pozitie)" function and i dont know what i do wrong... heres are the codes + attaches with all i'v done so far...

Qt Code:
  1. double MyMainWindow::calculeaza()
  2. {
  3. lastposition=aux-1;
  4. redo:
  5. if(lastposition>=1){
  6. myvect[lastposition-1]= QString::number(calcul(lastposition));
  7. lastposition-=2;}
  8. if(lastposition>0){goto redo;}
  9. return myvect[0].toDouble();
  10. }
  11. double MyMainWindow::calcul(int pozitie)
  12. {
  13. if (lastposition > pozitie)lastposition=pozitie;
  14. if(grad(pozitie)<grad(pozitie-2))
  15. {
  16. if(myvect[pozitie]=="+")
  17. return myvect[pozitie-1].toDouble() + calcul(pozitie-2);
  18. else if(myvect[pozitie]=="-")
  19. return myvect[pozitie-1].toDouble() - calcul(pozitie-2);
  20. else if(myvect[pozitie]=="x")
  21. return myvect[pozitie-1].toDouble() * calcul(pozitie-2);
  22. else if(myvect[pozitie]==":")
  23. return myvect[pozitie-1].toDouble() / calcul(pozitie-2);
  24. }
  25. else
  26. {
  27. if(myvect[pozitie]=="+")
  28. return myvect[pozitie-1].toDouble() + myvect[pozitie+1].toDouble();
  29. else if(myvect[pozitie]=="-")
  30. return myvect[pozitie-1].toDouble() - myvect[pozitie+1].toDouble();
  31. else if(myvect[pozitie]=="x")
  32. return myvect[pozitie-1].toDouble() * myvect[pozitie+1].toDouble();
  33. else if(myvect[pozitie]==":")
  34. return myvect[pozitie-1].toDouble() / myvect[pozitie+1].toDouble();
  35. }
  36. return 0;
  37. }
  38. int MyMainWindow::grad(int pozitie)
  39. {
  40. if(pozitie<0)return 0;
  41. if(myvect[pozitie]=="+"||myvect[pozitie]=="-") return 1;
  42. if(myvect[pozitie]==":"||myvect[pozitie]=="x") return 2;
  43. return 0;
  44. }
To copy to clipboard, switch view to plain text mode 



here is a link with all i've done...http://www.4shared.com/file/Quv4vcMG/mycalc.html



thx