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

I am having trouble with my assignment and getting compile errors on the following code. The...
I am having trouble with my assignment and getting compile errors on the following code. The instructions are in the initial comments. /* Chapter 5, Exercise 2 -Write a class "Plumbers" that handles emergency plumbing calls. -The company handles natural floods and burst pipes. -If the customer selects a flood, the program must prompt the user to determine the amount of damage for pricing. -Flood charging is based on the numbers of damaged rooms. 1 room costs $300.00, 2 rooms...
I am using a Macbook and trying to use the terminal and a VIM editor to...
I am using a Macbook and trying to use the terminal and a VIM editor to create program. This program will allow you to enter the costs of each ingredient and product, then prompt for the amount of each ingredient bought (individually by ingredient) and product sold (also individually), and from there show profit or loss, as well as profit on average for each unit sold. There will be say, 2 ingredients to buy and 3 products to sell. Please...
I am having trouble fixing my build errors. The compiler I am using is Visual Studio.Thanks....
I am having trouble fixing my build errors. The compiler I am using is Visual Studio.Thanks. #include <iostream> #include <string> #include <cstdlib> using namespace std; /* * structure to store employee details * employee details are stored as linked list */ struct Employee { private:    string full_name; //full name    double net_income; //income public:    struct Employee *next; //pointing to the next employee details in the list                        /*                   ...
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....
C++ Bank Account Error Fix, full code. I am using Dev-C++ to Compile and Execute. The...
C++ Bank Account Error Fix, full code. I am using Dev-C++ to Compile and Execute. The project is below, I have supplied the code and I'm getting an error in SavingsAccount.h file. 17   5   C:\Users\adam.brunell\Documents\Classes\C++\Week4\SavingsAccount.h   [Error] 'SavingsAccount::SavingsAccount(std::string, double, double)' is protected A.Assume i.SavingsAccount: Assume an Interest Rate of 0.03 ii.HighInterestSavings: Assume an Interest Rate of 0.05, Minimum Balance = $2500 iii.NoServiceChargeChecking: Assume an Interest Rate = 0.02, Minimum of Balance = $1000 iv.ServiceChargeChecking – Assume account service charge = $10,...
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 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;
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("...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT