Results 1 to 3 of 3

Thread: i don't know what i do wrong..

  1. #1
    Join Date
    May 2010
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation i don't know what i do wrong..

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: i don't know what i do wrong..

    Can you explain what the problem is?

    One thing I noticed is that you check for "x" when multiplying and in your description you use *

  3. #3
    Join Date
    May 2010
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: i don't know what i do wrong..

    it dosn't work ....download the link and u will see...

Similar Threads

  1. what is wrong with my qt ?
    By lwb422 in forum Qt Programming
    Replies: 5
    Last Post: 12th April 2010, 14:07
  2. PyQt... What am I doing wrong?!
    By Richie in forum Newbie
    Replies: 2
    Last Post: 4th September 2009, 17:14
  3. What's wrong??
    By dreamer in forum Qt Programming
    Replies: 2
    Last Post: 25th June 2008, 08:07
  4. What is wrong with this simple example ?
    By igor in forum Qt Programming
    Replies: 10
    Last Post: 16th January 2007, 11:26
  5. Help please - what am I doing wrong?
    By Jimmy2775 in forum Qt Programming
    Replies: 6
    Last Post: 6th March 2006, 22:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.