What's wrong in my code?? #include using namespace std; int main () { int basicSalary, bonus = 0, years, newsalary; char gender; cout << "Enter the basic salary amount: "; cin >> basicSalary; cout << "Enter the number of years: "; cin >> years; cout << "Enter if the employee is F for Female or M for Male: "; if (years > 5 && gender == 'F') bonus = years * 20; else
What's wrong in my code??
#include <iostream>
using namespace std;
int main ()
{
int basicSalary, bonus = 0, years, newsalary;
char gender;
cout << "Enter the basic salary amount: ";
cin >> basicSalary;
cout << "Enter the number of years: ";
cin >> years;
cout << "Enter if the employee is F for Female or M for Male: ";
if
(years > 5 && gender == 'F')
bonus = years * 20;
else
(years < 5 && gender == 'F')
bonus = years * 10;
else
(years > 5 && gender == 'M')
bonus = years * 40;
else
(years < 5 && gender == 'M')
bonus = years * 20;
newsalary = basicSalary + bonus cout << "Bonus amount is: " << bonus;
cout << "The new salary is " << newsalary;
return 0;
}
1: First error is that you missed to input gender, after asking to input gender
2: To check for multiple condition you can use if/else if conditional statements, but here you used only if/else conditionals after which following else blocks are worthless and raising errors
3: Next, when you were assign values for newsalary you missed a semi-colon in the end
4: (optional) just for formatting purpose. For printing bonus and newsalary new line at the end to print them in a separate line
Step by step
Solved in 3 steps with 2 images