Question

In: Computer Science

My code does not compile, I am using vim on terminal and got several compiling errors...

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;

}

Solutions

Expert Solution

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


Related Solutions

Here is my fibonacci code using pthreads. When I run the code, I am asked for...
Here is my fibonacci code using pthreads. When I run the code, I am asked for a number; however, when I enter in a number, I get my error message of "invalid character." ALSO, if I enter "55" as a number, my code automatically terminates to 0. I copied my code below. PLEASE HELP WITH THE ERROR!!! #include #include #include #include #include int shared_data[10000]; void *fibonacci_thread(void* params); void parent(int* numbers); int main() {    int numbers = 0; //user input....
I am getting 7 errors can someone fix and explain what I did wrong. My code...
I am getting 7 errors can someone fix and explain what I did wrong. My code is at the bottom. Welcome to the DeVry Bank Automated Teller Machine Check balance Make withdrawal Make deposit View account information View statement View bank information Exit          The result of choosing #1 will be the following:           Current balance is: $2439.45     The result of choosing #2 will be the following:           How much would you like to withdraw? $200.50      The...
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using...
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using namespace std; const int CWIDTH = 26; int main() {    int choice;    double convertFoC, converCtoF;    double starting, endvalue, incrementvalue;    const int CWIDTH = 13;    do {       cin >> choice;    switch (choice)    {        cin >> starting;    if (starting == 28){       cout << "Invalid range. Try again.";    }    while (!(cin >> starting)){       string  garbage;       cin.clear();       getline(cin, garbage);       cout << "Invalid data Type, must be a number....
I am creating SAS code, but am receiving an errors " ERROR: Value is out of...
I am creating SAS code, but am receiving an errors " ERROR: Value is out of range or inappropriate. ERROR: No body file. HTML5(WEB) output will not be created." This is the code: option ls=65 ps=65; data one; input IQ; cards; 145 139 122 ; title 'Normal Quantile - Quantile Plot for IQ'; ods graphics on; proc univariate data=one; qqplot IQ / normal (mu=est sigma=est); run;
Please fix this code I am having issues compiling it all together there is 3 codes...
Please fix this code I am having issues compiling it all together there is 3 codes here and it's giving me errors in my main method..... I feel like it might be something simple but I can't seem to find it. package assignement2; import java.util.ArrayList; import java.util.Scanner; public class reg1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the number of items: "); int number = input.nextInt(); input.nextLine(); for (int i = 0; i <...
I was wondering is someone could tell me why my code isn't compiling - Java ------------------------------------------------------------------------------------------------------------...
I was wondering is someone could tell me why my code isn't compiling - Java ------------------------------------------------------------------------------------------------------------ class Robot{ int serialNumber; boolean flies,autonomous,teleoperated; public void setCapabilities(int serialNumber, boolean flies, boolean autonomous, boolean teleoperated){ this.serialNumber = serialNumber; this.flies = flies; this.autonomous = autonomous; this.teleoperated = teleoperated; } public int getSerialNumber(){ return this.serialNumber; } public boolean canFly(){ return this.flies; } public boolean isAutonomous(){ return this.autonomous; } public boolean isTeleoperated(){ return this.teleoperated; } public String getCapabilities(){ StringBuilder str = new StringBuilder(); if(this.flies){str.append("canFly");str.append(" ");} if(this.autonomous){str.append("autonomous");str.append("...
I am currently having trouble understanding/finding the errors in this python code. I was told that...
I am currently having trouble understanding/finding the errors in this python code. I was told that there are 5 errors to fix. Code: #!/usr/bin/env python3 choice = "y" while choice == "y": # get monthly investment monthly_investment = float(input(f"Enter monthly investment (0-1000):\t")) if not(monthly_investment > 0 and monthly_investment <= 100): print(f"Entry must be greater than 0 and less than or equal to 1000. " "Please start over.")) #Error 1 extra ")" continue # get yearly interest rate yearly_interest_rate = float(input(f"Enter...
This is my code for python. I am trying to do the fourth command in the...
This is my code for python. I am trying to do the fourth command in the menu which is to add an employee to directory with a new phone number. but I keep getting error saying , "TypeError: unsupported operand type(s) for +: 'dict' and 'dict". Below is my code. What am I doing wrong? from Lab_6.Employee import * def file_to_directory(File): myDirectory={}       with open(File,'r') as f: data=f.read().split('\n')    x=(len(data)) myDirectory = {} for line in range(0,199):      ...
I'm getting an error with my code on my EvenDemo class. I am supposed to have...
I'm getting an error with my code on my EvenDemo class. I am supposed to have two classes, Event and Event Demo. Below is my code.  What is a better way for me to write this? //******************************************************** // Event Class code //******************************************************** package java1; import java.util.Scanner; public class Event {    public final static double lowerPricePerGuest = 32.00;    public final static double higherPricePerGuest = 35.00;    public final static int cutOffValue = 50;    public boolean largeEvent;    private String...
***The code is provided below*** When trying to compile the code below, I'm receiving three errors....
***The code is provided below*** When trying to compile the code below, I'm receiving three errors. Can I get some assistance on correcting the issues? I removed the code because I thought I corrected my problem. I used #define to get rid of the CRT errors, and included an int at main(). The code compiles but still does not run properly. When entering the insertion prompt for the call details, after entering the phone number, the program just continuously runs,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT