I am trying to get better at C++ by challenging myself by creating a program that manages employees. Given a certain salary vs. sales you will either be hired, fired or keep your job. I have been working with OOP a lot recently and thought that structuring it by class would make the exercise easier. I've gone over this again and again and I can't seem to find a solution. That being said I would very much appreciate some insight on what I am doing wrong. Keep in mind I am new to C++ and OOP but the more I learn the better I will be in the future.
Originally it was all one file then I separated the classes into header files. It seems to run a little smoother now but I still get the error that name, salary and scope (my variables) aren't defined in the scope of my program.
main.cpp
#include "Boss.h"
#include "Employee.h"
#include "PotentialEmployee.h"
#include <iostream>
using namespace std;
int main ()
{
Boss Boss1;
Boss Boss2;
Boss Boss3;
Employee Employee1;
Employee Employee2;
Employee Employee3;
PotentialEmployee PotentialEmployee1;
PotentialEmployee PotentialEmployee2;
Employee1.name = "Michael";
Employee2.name = "John";
Employee3.name = "Lisa";
Boss1.name = "Luke";
Boss2.name = "Ben";
Boss3.name = "Jack";
PotentialEmployee1.name = "Bill";
PotentialEmployee2.name = "Fred";
Employee1.salary = 55000;
Employee2.salary = 65000;
Employee3.salary = 75000;
Boss1.salary = 88000;
Boss2.salary = 95000;
Boss3.salary = 88000;
PotentialEmployee1.salary = 55000;
PotentialEmployee2.salary = 65000;
Employee1.sales = 12000;
Employee2.sales = 40000;
Employee3.sales = 80000;
Boss1.sales = 200000;
Boss2.sales = 250000;
Boss3.sales = 280000;
PotentialEmployee1.sales = 55000;
PotentialEmployee2.sales = 65000;
if (sales <= salary)
std::cout << "I'm sorry " << name << "you have been fired";
else if (sales >= salary)
std::cout << "Good job " << name << "you get a bonus";
else
std::cout << "Try and do better next quarter";
return 0;
}
main.cpp: In function ‘int main()’: main.cpp:66:7: error: ‘sales’ was not declared in this scope if (sales <= salary) { ^ main.cpp:66:16: error: ‘salary’ was not declared in this scope if (sales <= salary) { ^ main.cpp:67:34: error: ‘name’ was not declared in this scope std::cout << "I'm sorry " << name << "you have been fired"; ^ main.cpp:71:35: error: ‘name’ was not declared in this scope std::cout << "Good job " << name << "you get a bonus";