mercredi 1 juillet 2020

I cant figure out why the program wont run after the last else statement. Can someone explain why? Also help me find a solution


// PC 5.19.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
using namespace std;

int main()
{

    double current_value,
    double total = 0.0;
    int years_decay, num;

    double budget, budget_surplus, budget_undercut;
    cout << "How much have you budgeted for this month ";
    cin >> budget;
    while (budget < 0)
    {
        cout << "Please enter a budget that is larger than 0 ";
        cin >> budget;
    }
    cout << "\t\tHere is a list of your expenses" << endl;
    cout << "1. Electricity expense" << endl;
    cout << "2. Water expense" << endl;
    cout << "3. Car expense" << endl;
    cout << "4. Television expense" << endl;
    cout << "5. Food expense" << endl;

    for (int count = 1;count < 6; count++)
    {
        
        double expenses;
        cout << "Enter the amount of money you have used for expense number " << count << " ";
        cin >> expenses;
        total += expenses;
    }
    if (budget > total)
    {
        budget_surplus = budget - total;
        cout << "You are $" << budget_surplus << " dollars under budget. Good for you!";
    }
    else if (total > budget)
    {
        budget_undercut = total - budget;
        cout << "You are $" << budget_undercut << " dollar over budget. Sorry";

    }
    else
    {
        cout << "Your budget is exactly equal to your expenses";
    }

    
    // The program stops working here?
    
    
    cout << "Please enter the amont of years for which you would like to calculate decay on the product. ";
    cin >> years_decay;
    cout << "Please enter the current value of the product ";
    cin >> current_value;

        for (num = 1; num <= years_decay; num++)
        {
            current_value *= .9;
            cout << "For year " << num << "the value of the product is " << current_value << endl;
        }
        
    return 0;
   
}

The program stops working after the else function with the cout << "Your budget is exactly equal to your expenses"

Aucun commentaire:

Enregistrer un commentaire