PDA

View Full Version : How to do this in QT?



qtnewbie12
31st July 2012, 02:57
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 .


void MainWindow::on_pushButton_clicked()
{
long salary ;
salary = ui->lineEdit->text().toLong();
if (salary<=5000)
{
QMessageBox::information(this,"salary",QString::number(salary));
}
else
if (salary>5000 && salary >=10000)
{


}
else
if (salary>10000)
{
}
}

can someone help me with the code?
Thanks in advance

sonulohani
31st July 2012, 06:30
void MainWindow::on_pushButton_clicked(){
int x,salary;
x=ui->lineEdit->text().toInt(0);
if(x<=5000){
salary=x;
QMessageBox::information(this,"Salary",QString::number(salary));
}
else if(x>=7000){
salary=x-5000;
salary=(salary*5)/100;
salary=x-salary;
QMessageBox::information(this,"Salary",QString::number(salary));
}
else if(x>=10000){
salary=x-(x*10/100);
QMessageBox::information(this,"Salary",QString::number(salary));
}
else if(x<10000 && x<20000){
salary=x-10000;
salary=salary*10/100;
salary=salary+250;
salary=x-salary;
QMessageBox::information(this,"Salary",QString::number(salary));
}
}


This is what i understood from your example. If you want any further help then you're welcome.

ChrisW67
31st July 2012, 07:03
I'd be more inclined to handling this (homework?) question the other way around:


float salary = 11000.0;
float tax = 0.0; // I wish ;)
if (salary > 10000.0)
tax = 0.10 * (salary - 10000.0) + 250.0; // 250 is the tax on the first 10000
else if (salary > 5000.0)
tax = 0.05 * (salary - 5000.0); // + 0.0; 0.0 is the tax on the first 5000
else
tax = 0.0;

In a real-world situation you will have all sorts of rounding rules to take into consideration.

qtnewbie12
3rd August 2012, 00:39
void MainWindow::on_pushButton_clicked(){
int x,salary;
x=ui->lineEdit->text().toInt(0);
if(x<=5000){
salary=x;
QMessageBox::information(this,"Salary",QString::number(salary));
}
else if(x>=7000){
salary=x-5000;
salary=(salary*5)/100;
salary=x-salary;
QMessageBox::information(this,"Salary",QString::number(salary));
}
else if(x>=10000){
salary=x-(x*10/100);
QMessageBox::information(this,"Salary",QString::number(salary));
}
else if(x<10000 && x<20000){
salary=x-10000;
salary=salary*10/100;
salary=salary+250;
salary=x-salary;
QMessageBox::information(this,"Salary",QString::number(salary));
}
}


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.


void MainWindow::on_pushButton_clicked()
{
int x,salary ;
x=ui->lineEdit->text().toLong(0);
if (x<=5000)
{
salary=x ;
QMessageBox::information(this,"salary",QString::number(salary));

}
else if (x>5000 && x<=10000)
{
salary=x-5000;
salary=(salary*5)/100 ;
salary=x-salary ;
QMessageBox::information(this,"salary",QString::number(salary));
}
else if (x>10000){
salary=x-10000;
salary= (salary*10)/100 ;
salary=salary+250 ;
salary=x-salary;
QMessageBox::information(this,"salary",QString::number(salary));

}
}