The purpose of the program is to tell the user that the weekly salary is in on of three ranges, less than 200, between 200 and 800 and greater than 800.
I need help knowing the error/s and need to add and use one additional preprocessor directive that might help with calculation or showing the results

#include <iostream>
using namespace std;

int main() {
    const int MAX_HOURS_IN_WEEK = 168;
    const int MAX_WAGE = 100;
    const int LOWER_SALARY = 200;
    const int UPPER_SALARY = 800;

    int hourlyWage;
    int workHoursPerWeek;
    int weeklySalary;

    cout << "How many hours do you work per week?" << endl;
    cin >> workHoursPerWeek;
    if (workHoursPerWeek < 0 && workHoursPerWeek > MAX_HOURS_IN_WEEK) {
        cout << "Invalid number of hours per week." << endl;
        return -1;
    }

    cout << "What is your hourly wage?" << endl;
    cin >> hourlyWage;
    if (hourlyWage > MAX_WAGE) {
        cout << "An hourly wage greater than 100 requires executive approval." << endl;
    } else if (hourlyWage < 0) {
        cout << "Invalid hourly wage." << endl;
        return -1;
    }

    weeklySalary = hourlyWage * workHoursPerWeek;

    if (weeklySalary < LOWER_SALARY) {
        cout << "The weekly salary is less than 200." << endl;
    }
    if (weeklySalary <= UPPER_SALARY) {
        cout << "The weekly salary is between 200 and 800." << endl;
    } else {
        cout << "The weekly salary is greater than 800." << endl;
    }

    return 0;
}

Recommended Answers

All 2 Replies

Small issue here. You didn't ask a question or tell us what the error was on what line.

You can use the preprocessor example in the manner to help calculate your weekly salary. It doesn't take overtime into account. Your salary comparisons were incorrect and left out conditions. You can easily find out what isn't working, by displaying what the calculations are entered. Decimal variable input wasn't taken. Determine the scope of your variables, local or global.

#include <iostream>
    double hourlyWage = 0.0;
    double workHoursPerWeek = 0.0;
    double weeklySalary = 0.0; 

#define salary(a) (workHoursPerWeek * hourlyWage)

    const int MAX_HOURS_IN_WEEK = 168;
    const int MAX_WAGE = 100;
    const int LOWER_SALARY = 200;
    const int UPPER_SALARY = 800;

int main() {

    while (1) {
        std::cout << "How many hours do you work per week: ";
        std::cin >> workHoursPerWeek;

         weeklySalary = salary(hourlyWage);

         if (workHoursPerWeek > MAX_HOURS_IN_WEEK || workHoursPerWeek < 0) {
             std::cout << "Invalid number of hours per week." << std::endl;
            return -1;
        }

        std::cout << "What is your hourly wage: ";
        std::cin >> hourlyWage;

        if (hourlyWage > MAX_WAGE) {
            std::cout << "An hourly wage greater than 100 requires executive approval." << std::endl;
        }
        else if (hourlyWage < 0) {
            std::cout << "Invalid hourly wage." << std::endl;
            return -1;
        }

        std::cout << " Hours: " << workHoursPerWeek << std::endl;
        std::cout << " Rate: $" << hourlyWage << std::endl;
        std::cout << " Weekly Salary: $" << salary(a) << std::endl;

        if (salary(a) < LOWER_SALARY) {
            std::cout << "The weekly salary is less than $200." << std::endl;
        }
        if (salary(a) <= UPPER_SALARY && salary(a) >= LOWER_SALARY) {
            std::cout << "The weekly salary is between $200 and $800." << std::endl;
        }
        if (salary(a) > UPPER_SALARY) {
            std::cout << "The weekly salary is greater than $800." << std::endl;
        }
        //reset
        hourlyWage = 0.0;
        workHoursPerWeek = 0.0;
        weeklySalary = 0.0;
    }
    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.