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
- Recommended textbooks for youDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSONDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSONC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag…Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education