This program calculates the service rate for tax assistance based on whether a client is low income or not and how much time they need.
The problem is that some if statements return 0 even though the operands are the correct numbers. Is this the dreaded null pointer I keep hearing about?
The problem is that some if statements return 0 even though the operands are the correct numbers. Is this the dreaded null pointer I keep hearing about?
#include <iostream>
#include <iomanip>
using namespace std;
//declare prototype for boolean lowIncome function
bool lowIncome(double income);
//declare prototype for billingAmount function
double billingAmount(double rate, int cTime, bool isLowIncome);
int main() {
    //declare global variables
    double income;
    double rate;
    bool isLowIncome;
    int cTime;
    double billAmount;
    //format to two decimal places
    cout << fixed << showpoint << setprecision(2);
    //prompt user for yearly income, place in income
    cout << "Enter yearly income: ";
    cin >> income;
    cout << endl;
    //prompt user for hourly rate, place in rate
    cout << "Enter hourly rate: ";
    cin >> rate;
    cout << endl;
    //prompt user for total consulting time in minutes
    cout << "Enter total consulting time in minutes: ";
    cin >> cTime;
    cout << endl;
    //capture low income status
    isLowIncome = lowIncome(income);
    //capture billing amount
    billAmount = billingAmount(rate, cTime, isLowIncome);
    //output billing amount to user
    cout << "The billing amount is: " << billAmount << endl;
    //cout << "Client is low income: " << isLowIncome;
    return 0;
}
//define lowIncome function
bool lowIncome(double income)
{
  if(income<=25000)
  {
    return true;
  } else 
    {
      return false;
    }
}
//define billingAmount function
double billingAmount(double rate, int cTime, bool isLowIncome)
{
  double billAmount = 1;
  int overtime;
  if (isLowIncome == true && cTime<=30)
  {
     billAmount = 1;
     cout << "bill 1 is: " << billAmount << endl;
  } else if (isLowIncome == true && cTime>30)
    {
      cTime = cTime - 30;
      billAmount = rate * .4 * (cTime/60);
      cout << "bill 2 is: " << billAmount << endl;
    } else if (isLowIncome == false && cTime<=20)
      {
        billAmount = 0;
      } else if (isLowIncome == false && cTime>20)
        {
          overtime = cTime - 20;
          billAmount = rate * .7 * (overtime/60);
          cout << "bill 3 is: " << billAmount << endl; 
        } else 
          {
            billAmount = 0;
          }
    return billAmount;
}
