**This is an old revision of the document!**

# BYU Health Insurance with booleans

## Problem

See BYU Health Insurance for original problem. This problem expands on that problem by requiring the use of a boolean variable to store the marital status AND checking for invalid input (i.e., invalid data type as opposed to invalid range).

## Solution

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

const string YES = "Y";

int main()
{
// INPUTS: whether single or married, dependents or no dependents

cout << fixed << setprecision(2);

string single_status = YES;
int dependents_count = 0;

// Prompt user
cout << "Are you single? (Y/N) ";
cin >> single_status;

// Define boolean based on the user input
bool is_single = (single_status == YES);

cout << "How many dependents do you have? ";
cin >> dependents_count;

if (cin.fail()) // tried to read an integer, but found something else => FAILURE!
{
cout << "Hey, give me an integer! ";
string dummy_input; // variable used to later consume the bad input
cin.clear(); // we mark the cin failure as now being resolved - THIS DOES NOT CLEAR WHAT IS IN cin
cin >> dummy_input; // consume the bad input
cin >> dependents_count; // get the new input
}

// Decide which premium they should pay
if (is_single)
{
if (dependents_count > 0)
{
}
else
{
}
}
else
{
if (dependents_count > 0)
{
}
else
{
}