#include<iostream> #include <iomanip> using namespace std; int main(){ double in
ID: 3743021 • Letter: #
Question
#include<iostream>
#include <iomanip>
using namespace std;
int main(){
double income,tax;
char sm;
int check;
char choice='y';
while(choice=='y')
{
check=1;
while (check==1)
{
check=0;
cout<<"Please enter in your taxable income.(This must be a positive value): "<<endl;
cin>>income;
if (income<0)
{
check=1;
cout<<"(This must be a positive value) ";
}
}
check=1;
while(check==1)
{
check=0;
cout<<"Please enter m if married and filing joint return, or s if filing a single return: ";
cin>>sm;
if(sm!='s'&&sm!='m')
{
check=1;
cout<<"Please enter a valid choice ";
}
}
if(sm=='s')
{
if(income<=863)
tax=(income*.023);
else if(income<=2588)
tax=(income-863)*.033+25;
else if(income<=4313)
tax=(income-2588)*.052+85;
else
tax=(income-4313)*.075+181;
cout<<setprecision(2)<<fixed;
cout<<"Your taxable income is $"<<income<<" and you are filing a single return. ";
}
else
{
if(income<=1726)
tax=(income*.023);
else if(income<=5176)
tax=(income-1726)*.033+40;
else if(income<=8626)
tax=(income-5176)*.052+175;
else
tax=(income-8626)*.075+390;
cout<<"Your taxable income is $"<<income<< " and you are filing a joint return. ";
}
cout<<"Your income tax will be $"<<tax<<endl;
check=1;
while(check==1)
{
check=0;
cout<<"Would you like to do another calculation (y or n)?";
cin>>choice;
if(choice!='y'&&choice!='n')
{
check=1;
cout<<"Invalid choice!!"<<endl;
}
}
}
return 0;
}
:Compare output 0/ Output differs. See highlights below. 500 Input s Please enter in your taxable income. (This must be a positive value): Please enter m if married and filing joint return, or s if filing a sing Your income tax will be $11.5 Would you like to do another calculation (y or n)? Your output Please enter in your taxable income. (This must be a positive value): Please enter m if married and filing joint return, or s if filing a single return: Expected output Your taxable income is $500.00 and you are filing a single return Your income tax will be $11.50 Would you like to do another calculation (y or n)?Explanation / Answer
#include<iostream>
#include <iomanip>
using namespace std;
int main(){
double income,tax;
char sm;
int check;
char choice='y';
while(choice=='y')
{
check=1;
while (check==1)
{
check=0;
cout<<"Please enter in your taxable income. (This must be a positive value): "<<endl;
cin>>income;
if (income<0)
{
check=1;
cout<<"(This must be a positive value) ";
}
}
check=1;
while(check==1)
{
check=0;
cout<<" Please enter m if married and filing joint return, or s if filing a single return: ";
cin>>sm;
if(sm!='s'&&sm!='m')
{
check=1;
cout<<"Please enter a valid choice ";
}
}
if(sm=='s')
{
if(income<=863)
tax=(income*.023);
else if(income<=2588)
tax=(income-863)*.033+25;
else if(income<=4313)
tax=(income-2588)*.052+85;
else
tax=(income-4313)*.075+181;
cout<<setprecision(2)<<fixed;
cout<<" Your taxable income is $"<<income<<" and you are filing a single return. ";
}
else
{
if(income<=1726)
tax=(income*.023);
else if(income<=5176)
tax=(income-1726)*.033+40;
else if(income<=8626)
tax=(income-5176)*.052+175;
else
tax=(income-8626)*.075+390;
cout<<"Your taxable income is $"<<income<< " and you are filing a joint return. ";
}
cout<<"Your income tax will be $"<<tax<<endl;
check=1;
while(check==1)
{
check=0;
cout<<" Would you like to do another calculation (y or n)?";
cin>>choice;
if(choice!='y'&&choice!='n')
{
check=1;
cout<<"Invalid choice!!"<<endl;
}
}
}
return 0;
}
output:
Please enter in your taxable income.
(This must be a positive value):500
Please enter m if married and filing joint return,
or s if filing a single return:s
Your taxable income is $500.00
and you are filing a single return.
Your income tax will be $11.50
Would you like to do another calculation (y or n)?n
Just add newline character in " " quotes.
Do ask if any doubt. Please upvote.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.