In: Computer Science
My code does not compile, I am using vim on terminal and got several compiling errors this is C++ language I need help fixing my code below is the example expected run and my code.
Example run (User inputs are highlighted):
Enter your monthly salary: 5000
Enter number of months you worked in the past year: 10 Enter the
cost of the car: 36000
Enter number of cars you’ve sold in the past year: 30 Enter number
of misconducts observed in the past year: 4 Which tax year are you
in, enter 1 for 2018, 2 for 2019: 1 Which state are you in, enter
A, B, or C: C
The average selling price, generated randomly, is $38000, you will earn 2% of the profit, which is $1200.
The gross income is: $50400
The tax you need to pay is: $4286 Remaining: $46114
BELOW IS MY CODE.
#include <iostream>
#include <cmath>
using namespace std;
int main() {
float salary,cost,tax;
int months,cars,misconducts,year;
float annual_salary,profit,rand_price,deduction,gross_income=0,income;
char state;
/* Take monthly slary from user. */
cout<<”Enter your monthly salary: ";
cin>>salary;
cout<<endl;
/* takes the number of months you worked in the past year from the user. */
cout<<”Enter the number of months you worked in the past year: ";
cin>>months;
cout<<endl;
/* take the cost of car from the user. */
cout<<”Enter the cost of the car: ";
cin>>cost;
cout<<endl;
/* take the number of cars sold in the past year from user. */
cout<<Enter number of car’s that you’ve sold in the past year: ";
cin>>cars;
cout<<endl;
/* takes number of misconducts observed in the past year. */
cout<<”Enter number of misconducts observed in the past year: ";
cin>>misconducts;
cout<<endl;
/* take tax year from user */
cout<<”Which tax year are you in enter 1 for 2018, 2 for 2019: ";
cin>>tax_year;
cout<<endl;
/* take state from the user */
cout<<”Which state are you in, enter A, B or C: ";
cin>>state;
cout<<endl<<endl;
annual_salary=salary*months;
rand_price=((rand()%5+6)+100)*0.01*cost; /* generate random number between 5 and 10 */
profit=cars*(rand_price-cost);
if(misconduct==0)
{
deduction=0;
}
else
{
deduction=100*(pow(2,misconducts-1));
}
/* calculate the gross income */
gross_income=annual_salary+0.02*(profit)-deduction;
income=gross_income;
/* calculate the tax based on state and tax_year */
/* check if tax_year=1 */
if(tax_year=1)
{
/* check state is A */
if(state==’A')
{
tax=0.06*income;
}
/* check state is B */
else if(state=='B')
{
if(income<2000)
{
tax=0;
}
else if(income>2000 && income<10000)
{
tax=100;
}
else
{
tax=0.1*income+100;
}
}
/* state is C */
else if(state=='C')
{
if(income>0 && income<3500)
{
tax=0.05*income;
}
else if(income>3500 && income<9000)
{
tax=0.07*income+175;
}
else if(income>9000 && income<125000)
{
tax=0.09*income+560;
}
else
{
tax=0.099*income+11000;
}
}
else
{
tax=0;
}
}
/* check tax_year if it equals to 2 */
else if(tax_year==2)
{ //check state is A
if(state=='A')
{
tax=0.08*income;
}
/* check state is B */
else if(state=='B')
{
if(income<2500)
{
tax=0;
}
else if(income>2500 && income<10000)
{
tax=115;
}
Else
{
tax=0.105*income+115;
}
}
/* check state is C */
else if(state=='C')
{
if(income>0 && income<3450)
{
tax=0.05*income;
}
else if(income>3450 && income<8700)
{
tax=0.07*income+172.5;
}
else if(income>3450 && income 8700)
{
tax=0.07*income+172.5;
}
else if(income>8700 && income<125000)
{
tax=0.09*income+540;
}
else
{
tax=0.099*income+11007;
}
}
else
{
tax=0;
}
}
else
{
tax=0;
}
/* print gross_income and the tax */
cout<<"The average selling price, generated randomly, is $"<<rand_price<<", you will earn 2% of the profit, which is $"<<profit*0.02<<endl;
cout<<endl;
cout<<"The gross income is: $"<<gross_income<<endl;
cout<<"The tax you need to pay is: $"<<tax<<endl;
cout<<"Remaining: $"<<gross_income-tax<<endl;
return 0;
}
Here is a code which contains no error upon compilation............Dear student at one place you have written the same code two times thats why i have comment it
#include<bits/stdc++.h>
#include <iostream>
#include <cmath>
using namespace std;
int main() {
float salary,cost,tax;
int months,cars,misconducts,year,tax_year;
float annual_salary,profit,rand_price,deduction,gross_income=0,income;
char state;
/* Take monthly slary from user. */
cout<<"Enter your monthly salary: ";
cin>>salary;
cout<<endl;
/* takes the number of months you worked in the past year from the user. */
cout<<"Enter the number of months you worked in the past year: ";
cin>>months;
cout<<endl;
/* take the cost of car from the user. */
cout<<"Enter the cost of the car: ";
cin>>cost;
cout<<endl;
/* take the number of cars sold in the past year from user. */
cout<<"Enter number of car’s that you’ve sold in the past year: ";
cin>>cars;
cout<<endl;
/* takes number of misconducts observed in the past year. */
cout<<"Enter number of misconducts observed in the past year: ";
cin>>misconducts;
cout<<endl;
/* take tax year from user */
cout<<"Which tax year are you in enter 1 for 2018, 2 for 2019: ";
cin>>tax_year;
cout<<endl;
/* take state from the user */
cout<<"Which state are you in, enter A, B or C: ";
cin>>state;
cout<<endl<<endl;
annual_salary=salary*months;
rand_price=((rand()%5+6)+100)*0.01*cost; /* generate random number between 5 and 10 */
profit=cars*(rand_price-cost);
if(misconducts==0)
{
deduction=0;
}
else
{
deduction=100*(pow(2,misconducts-1));
}
/* calculate the gross income */
gross_income=annual_salary+0.02*(profit)-deduction;
income=gross_income;
/* calculate the tax based on state and tax_year */
/* check if tax_year=1 */
if(tax_year==1)
{
/* check state is A */
if(state=='A')
{
tax=0.06*income;
}
/* check state is B */
else if(state=='B')
{
if(income<2000)
{
tax=0;
}
else if(income>2000 && income<10000)
{
tax=100;
}
else
{
tax=0.1*income+100;
}
}
/* state is C */
else if(state=='C')
{
if(income>0 && income<3500)
{
tax=0.05*income;
}
else if(income>3500 && income<9000)
{
tax=0.07*income+175;
}
else if(income>9000 && income<125000)
{
tax=0.09*income+560;
}
else
{
tax=0.099*income+11000;
}
}
else
{
tax=0;
}
}
/* check tax_year if it equals to 2 */
else if(tax_year==2)
{ //check state is A
if(state=='A')
{
tax=0.08*income;
}
/* check state is B */
else if(state=='B')
{
if(income<2500)
{
tax=0;
}
else if(income>2500 && income<10000)
{
tax=115;
}
else
{
tax=0.105*income+115;
}
}
/* check state is C */
else if(state=='C')
{
if(income>0 && income<3450)
{
tax=0.05*income;
}
else if(income>3450 && income<8700)
{
tax=0.07*income+172.5;
}
/* seems unnecessary
else if(income>3450 && income 8700)
{
tax=0.07*income+172.5;
} */
else if(income>8700 && income<125000)
{
tax=0.09*income+540;
}
else
{
tax=0.099*income+11007;
}
}
else
{
tax=0;
}
}
else
{
tax=0;
}
/* print gross_income and the tax */
cout<<"The average selling price, generated randomly, is $"<<rand_price<<", you will earn 2% of the profit, which is $"<<profit*0.02<<endl;
cout<<endl;
cout<<"The gross income is: $"<<gross_income<<endl;
cout<<"The tax you need to pay is: $"<<tax<<endl;
cout<<"Remaining: $"<<gross_income-tax<<endl;
return 0;
}
your output will depend on the logic ......i have only corrected your compilation error........if you need any help you can comment it