Table of Contents

Cougar Cash

Problem Statement

Solution

/*
Test Case 1:
Input: 8.50 (input less than initial balance)
Output: balance is 1.50
Actual: balance is 1.50
 
Test Case 2:
Input: 15.00 (input greater than initial balance)
Output: balance is 0, owes 5.00
Actual: balance is 0, owes 5.00
 
Test Case 3:
Input: 0 (border case)
Output: balance is 10
Actual: balance is 10
*/
 
#include <iostream>
#include <iomanip>
#include <string>
 
using namespace std;
 
const double INITIAL_BALANCE = 10.00;
 
int main()
{
	// inputs: how much they want to spend
	// outputs: balance after purchase, cash owed
	cout << fixed << setprecision(2);
 
	// Prompt the user
	double desired_expenditure;
	double balance = INITIAL_BALANCE;
 
	cout << "How much you wanna spend on bears? $";
	cin >> desired_expenditure;
 
	// if input > balance
	if (desired_expenditure > balance)
	{
 
		// report (input - balance) as still owed
		cout << "$" << (desired_expenditure - balance) << " is still owed" << endl;
		// update balance to 0
		balance = 0;
 
	}
	// otherwise
	else
	{
		// balance = balance - input
		balance -= desired_expenditure;
	}
 
	// print balance
	cout << "Your new balance is $" << balance << endl;
 
	system("pause");
	return 0;
}