-3

I cant seem to see my error here. relatively new to C++. Please help.

#include <iostream>
using namespace std;

int main()
{
    float salary,taxrate,incometax;

    cout << "Enter your Annual Salary" << endl;
    cin >> salary;

    if (salary>= 70000)
      taxrate = 0.4;
      incometax= taxrate*salary;
    else if
      taxrate= 0.3;
      incometax= taxrate*salary;

cout << "The income tax due is: R"<< incometax;

I am looking through my code and cannot find the error?

  • 4
    It looks like you're trying to write Python code, where indentation is used for scoping. It's not like that in C++. I recommend you get a couple of [good beginners books](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) to read. – Some programmer dude Aug 19 '17 at 16:33

2 Answers2

2

The else if needs a condition to evaluate. So something like else if(some condition){...}.

If you're looking to default after the first if fails, just use else{...}.

Also, you need curly braces around your if and else blocks, and at the end of main.

#include <iostream>
using namespace std;

int main()
{
    float salary,taxrate,incometax;

    cout << "Enter your Annual Salary" << endl;
    cin >> salary;

    if (salary>= 70000){
      taxrate = 0.4;
      incometax= taxrate*salary;
    }
    else{
      taxrate= 0.3;
      incometax= taxrate*salary;
    }

    cout << "The income tax due is: R"<< incometax;
}
Cuber
  • 713
  • 4
  • 17
0

Your code has some syntax and logical errors. Like else if() have to given condition, income will be modified twice if you will not put parenthesis. I will suggest you to follow some tutorial for learning syntax of language.

modified code is below with changes described as comments .

#include <iostream>
   using namespace std;

    int main()
    {
        float salary,taxrate,incometax;

        cout << "Enter your Annual Salary" << endl;
        cin >> salary;

        if (salary>= 70000)//without braces {} if includes only one statement in it
          taxrate = 0.4;
        else         //else if() have to given a condition so use else instead
          taxrate= 0.3;

          incometax= taxrate*salary;//it is conman for both so no need to put it 2 times  

    cout << "The income tax due is: R"<< incometax;
Mohit Yadav
  • 471
  • 8
  • 17