Results 1 to 4 of 4

Thread: How to do this in QT?

  1. #1

    Default How to do this in QT?

    Hello,
    I am so new to QT , I wanted to create an application that calculates the salary after exclusion of taxes.The application has 1 lineedit for the user to put his salary and 1 push button so when the user click it his salary after the exclusion of taxes appears on a messagebox .There are three cases to calculate the salary after the exclusion of taxes
    case 1 :
    if salary is less than or equals 5000 , in this case taxes equals zero so the salary would be the same.
    example:
    if the user put his salary in the lineedit 5000 then clicked the push button ,a messagebox will appear showing 5000"and I have no problem with this case .

    case 2 :
    if salary is more than 5000 and less than or equals 10000 and in this case the taxes for the 1st 5000 of the salary = 0 but the taxes for any money above 5000 would be 5%
    example :
    if salary is 7000
    then the taxes for the 1st 5000 =0
    and the taxes for the money above 5000 is %5
    7000-5000=2000*5=10000/100=100 so the taxes is 100
    and the salary after taxes = 7000-100= 6900
    and the problem in this case is I don't know how to write the code for it
    I want a code for a messagebox showing the salary after doing all the math above

    case 3 :
    if salary is more than 10000 , the taxes for the 1st 5000 is zero and the second 5000 is 5% and any money above 10000 is 10%
    example:
    if salary is 11000
    the taxes for 1st 5000 is zero
    and the taxes for the 2nd 5000 is 5000*5/100=250
    and the taxes for the money above 10000 which is 1000 in this example is 1000*10/100=100
    so the total of taxes is 250+100=350
    so the salary after taxes would be 11000-350=10650
    and I have a problem with this case same as case 2 .

    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. long salary ;
    4. salary = ui->lineEdit->text().toLong();
    5. if (salary<=5000)
    6. {
    7. QMessageBox::information(this,"salary",QString::number(salary));
    8. }
    9. else
    10. if (salary>5000 && salary >=10000)
    11. {
    12.  
    13.  
    14. }
    15. else
    16. if (salary>10000)
    17. {
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 
    can someone help me with the code?
    Thanks in advance

  2. #2
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Cool Re: How to do this in QT?

    Qt Code:
    1. void MainWindow::on_pushButton_clicked(){
    2. int x,salary;
    3. x=ui->lineEdit->text().toInt(0);
    4. if(x<=5000){
    5. salary=x;
    6. QMessageBox::information(this,"Salary",QString::number(salary));
    7. }
    8. else if(x>=7000){
    9. salary=x-5000;
    10. salary=(salary*5)/100;
    11. salary=x-salary;
    12. QMessageBox::information(this,"Salary",QString::number(salary));
    13. }
    14. else if(x>=10000){
    15. salary=x-(x*10/100);
    16. QMessageBox::information(this,"Salary",QString::number(salary));
    17. }
    18. else if(x<10000 && x<20000){
    19. salary=x-10000;
    20. salary=salary*10/100;
    21. salary=salary+250;
    22. salary=x-salary;
    23. QMessageBox::information(this,"Salary",QString::number(salary));
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 

    This is what i understood from your example. If you want any further help then you're welcome.
    Heavy Metal Rules. For those about to rock, we salute you.
    HIT THANKS IF I HELPED.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to do this in QT?

    I'd be more inclined to handling this (homework?) question the other way around:
    Qt Code:
    1. float salary = 11000.0;
    2. float tax = 0.0; // I wish ;)
    3. if (salary > 10000.0)
    4. tax = 0.10 * (salary - 10000.0) + 250.0; // 250 is the tax on the first 10000
    5. else if (salary > 5000.0)
    6. tax = 0.05 * (salary - 5000.0); // + 0.0; 0.0 is the tax on the first 5000
    7. else
    8. tax = 0.0;
    To copy to clipboard, switch view to plain text mode 
    In a real-world situation you will have all sorts of rounding rules to take into consideration.

  4. #4

    Default Re: How to do this in QT?

    Quote Originally Posted by sonulohani View Post
    Qt Code:
    1. void MainWindow::on_pushButton_clicked(){
    2. int x,salary;
    3. x=ui->lineEdit->text().toInt(0);
    4. if(x<=5000){
    5. salary=x;
    6. QMessageBox::information(this,"Salary",QString::number(salary));
    7. }
    8. else if(x>=7000){
    9. salary=x-5000;
    10. salary=(salary*5)/100;
    11. salary=x-salary;
    12. QMessageBox::information(this,"Salary",QString::number(salary));
    13. }
    14. else if(x>=10000){
    15. salary=x-(x*10/100);
    16. QMessageBox::information(this,"Salary",QString::number(salary));
    17. }
    18. else if(x<10000 && x<20000){
    19. salary=x-10000;
    20. salary=salary*10/100;
    21. salary=salary+250;
    22. salary=x-salary;
    23. QMessageBox::information(this,"Salary",QString::number(salary));
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 

    This is what i understood from your example. If you want any further help then you're welcome.
    Thank you so much for your help . I finished the application and its working perfectly.
    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. int x,salary ;
    4. x=ui->lineEdit->text().toLong(0);
    5. if (x<=5000)
    6. {
    7. salary=x ;
    8. QMessageBox::information(this,"salary",QString::number(salary));
    9.  
    10. }
    11. else if (x>5000 && x<=10000)
    12. {
    13. salary=x-5000;
    14. salary=(salary*5)/100 ;
    15. salary=x-salary ;
    16. QMessageBox::information(this,"salary",QString::number(salary));
    17. }
    18. else if (x>10000){
    19. salary=x-10000;
    20. salary= (salary*10)/100 ;
    21. salary=salary+250 ;
    22. salary=x-salary;
    23. QMessageBox::information(this,"salary",QString::number(salary));
    24.  
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 

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
  •  
Qt is a trademark of The Qt Company.