Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Why does the program ends prematurely

$
0
0
#include <iostream> 
#include <iomanip> // manipulate display sigs
#include <cmath> // math functions
#include <string> 
#include <windows.h> // Enables delay in proggy

using namespace std;
int main()
{
          //Distribution Service Charge - 3 parts
double Basic_Charge,Distribution_kWh_ChargeA,Distribution_kWh_ChargeB,RiderC1A,
RiderC2A;
         //Electricity Supply Service (ESS) Charge - 3 parts
double Generation_A1,Generation_A2,Generation_B1,Generation_B2; //Sum/Winter Mo
double Rider_S,Rider_B,Rider_W,Rider_R; //Riders
// Transmission
double Transmission_kW_Charge,Rider_T1; \
//Fuel Charge (RiderA)
double Rider_A;
         //Sales and Use Surcharge
double Sales_N_U_Rate;
         //State/Local Consumption Tax
//0 - 2500 kWh:
    double State_Consumption_A,
           Special_Regulatory_A,
           Local_Consumption_A;
//2501-50k kWh:
    double State_Consumption_B,
           Special_Regulatory_B,
           Local_Consumption_B;
//50k+
    double State_Consumption_C,
           Special_Regulatory_C,
           Local_Consumption_C;
//Va Beach tax
double VB_U_Tax;
//Late
double Late_Penalty;
                        //Miscellenaous
int Month,Days,Initial_meter_reading,Final_meter_reading,Energy_Used,
Number_of_days_in_billing_period;


double kWh,Balance_Forward,Distribution_Service_Charge,Generation,
Transmission,Fuel_Charge,Sales_and_Use_Surcharge,State_and_Local_Consumption_Tax
,Late_Payment_Charge,Total_Current_Charges,Total_Account_Balance,
Average_Daily_Cost,Current_Charges_Without_Tax,VB_U_Total,Previous_Balance;

string Name, Prompt;
Prompt = ", Please follow all directions.";

//Proggy Intro
cout << "Please enter your name customer: ";
cin >> Name;
//Sleep(200);
system("CLS");
//Sleep(1300);
cout << "Welcome, ";
//Sleep(500);
cout << Name << " To";
//Sleep(700);
cout << " Calculation of ";
//Sleep(800);
cout << "Electric Power Bill!\n"; // Ends
system("Pause");
system("CLS");
///////////
//Constant Values
    Basic_Charge=7.00;
    RiderC1A= 0.00010;                                                                              
    RiderC2A= 0.00024;
    Distribution_kWh_ChargeA= 0.02269;
    Distribution_kWh_ChargeB= 0.01296;
    kWh = 800.00;
    State_Consumption_A= 0.00102; 
    Special_Regulatory_A= 0.00012;
    Local_Consumption_A= 0.00038;
    State_Consumption_B= 0.00065;
    Special_Regulatory_B= 0.00008;
    Local_Consumption_B= 0.00024;
    State_Consumption_C= 0.00050;
    Special_Regulatory_C= 0.00006;
    Local_Consumption_C= 0.00018;
    VB_U_Tax= 3.00;             

cout << setw(15) << Name << Prompt << endl; //Added Flavor

cout << "\nPlease enter your initial meter reading: "; 
cin >> Initial_meter_reading;
cout << "\nPlease enter your final meter reading: "; 
cin >> Final_meter_reading;

system("CLS");
cout << setw(15) << Name << Prompt << endl;    
if (Final_meter_reading < Initial_meter_reading)
    Energy_Used = (Final_meter_reading + 100000) - Initial_meter_reading;
 else
      Energy_Used = Final_meter_reading - Initial_meter_reading;
      
                  //Distribution Charge Calculations    
 if (Energy_Used > 800 && Energy_Used <= 2500 && Final_meter_reading >= 00000 
    && Final_meter_reading <= 99999 && Initial_meter_reading >= 00000 
    && Initial_meter_reading <= 99999) 
    {
      Distribution_Service_Charge = Basic_Charge + ((Distribution_kWh_ChargeA)
    *(kWh)) + ((Distribution_kWh_ChargeB)*(Energy_Used - kWh)) + ((RiderC1A)
    *(Energy_Used)) + ((RiderC2A)*(Energy_Used));
    State_and_Local_Consumption_Tax = ((State_Consumption_A)*(Energy_Used)) + 
    ((Special_Regulatory_A)*(Energy_Used)) + ((Local_Consumption_A)
    *(Energy_Used));
     }
 else if (Energy_Used > 800 && Energy_Used >= 2500 && Energy_Used <= 50000 
 && Final_meter_reading >= 00000 && Final_meter_reading <= 99999 
 && Initial_meter_reading >= 00000 && Initial_meter_reading <= 99999)
   {
     Distribution_Service_Charge = Basic_Charge + ((Distribution_kWh_ChargeA)
     *(kWh)) + ((Distribution_kWh_ChargeB)*(Energy_Used - kWh)) + ((RiderC1A)
     *(Energy_Used)) + ((RiderC2A)*(Energy_Used));
     State_and_Local_Consumption_Tax = ((State_Consumption_B)/>/>*(Energy_Used)) 
     + ((Special_Regulatory_B)/>/>*(Energy_Used)) + ((Local_Consumption_B)/>/>
     *(Energy_Used));
     }
  else if (Energy_Used > 800 && Energy_Used > 50000 
  && Final_meter_reading >= 00000 && Final_meter_reading <= 99999 
  && Initial_meter_reading >= 00000 && Initial_meter_reading <= 99999)
  {
     Distribution_Service_Charge = Basic_Charge + ((Distribution_kWh_ChargeA)*
     (kWh)) + ((Distribution_kWh_ChargeB)*(Energy_Used - kWh)) + ((RiderC1A)*
     (Energy_Used)) + ((RiderC2A)*(Energy_Used));
     State_and_Local_Consumption_Tax = ((State_Consumption_C)*(Energy_Used)) + 
     ((Special_Regulatory_C)*(Energy_Used)) + ((Local_Consumption_C)
     *(Energy_Used));
     }
  else if (Energy_Used <= 800 && Final_meter_reading >= Initial_meter_reading 
  && Final_meter_reading >= 00000 && Final_meter_reading <= 99999 
  && Initial_meter_reading >= 00000 && Initial_meter_reading <= 99999)
  {
     Distribution_Service_Charge = Basic_Charge + ((Distribution_kWh_ChargeA)
     *(kWh)) + ((RiderC1A)*(Energy_Used)) + ((RiderC2A)*(Energy_Used));
     }
  else if (Energy_Used < 800 && Final_meter_reading <= Initial_meter_reading 
  && Final_meter_reading >= 00000 && Final_meter_reading <= 99999 
  && Initial_meter_reading >= 00000 && Initial_meter_reading <= 99999)
  {
     Distribution_Service_Charge = Basic_Charge + ((Distribution_kWh_ChargeA)
     *(kWh)) + ((RiderC1A)*(Energy_Used + 10000)) + ((RiderC2A)
     *(Energy_Used + 10000));
     }
     else 
     return 1;
     
              //Electricity Supply Service (ESS) Charge Calculations
//Constant Values
    Generation_A1 = 0.03795;       //June - Sept x < 800 ; Summer
    Generation_A2 = 0.05773;       // Over 800 kWh
    Generation_B1 = 0.03795;       //Oct - May x < 800 ; Winter 
    Generation_B2 = 0.02927;       // Over 800 kWh
    Rider_S = 0.00474;
    Rider_B = 0.00012;
    Rider_W = 0.00066;
    Rider_R = 0.00142;
    Rider_A = 0.02706;
    Transmission_kW_Charge = 0.0097;
    Rider_T1 = 0.00267;             //Subtract
    Sales_N_U_Rate = 0.00061;
//ESS Charge
Sales_and_Use_Surcharge = Sales_N_U_Rate*Energy_Used;    
Fuel_Charge = Rider_A*Energy_Used;    
Transmission = ((Transmission_kW_Charge)*(Energy_Used))-((Rider_T1)
*(Energy_Used));
                           //Months                           
cout << "\nPlease input a Month (ie: 1. January etc): ";
cin >> Month;
   
//Summer Rates
     if (Month== 9 || Month==7 || Month== 8
      || Month== 6)      
   {
         if (Energy_Used > 800 && Final_meter_reading >= 00000
           && Final_meter_reading <= 99999 && Initial_meter_reading >= 00000 
           && Initial_meter_reading <= 99999)
          {
          Generation = ((Generation_A1)*(kWh)) + ((Generation_A2)
         *(Energy_Used - kWh))
          + ((Rider_S)*(Energy_Used)) + ((Rider_B)/>/>*(Energy_Used)) + ((Rider_W)
           *(Energy_Used)) + ((Rider_R)*(Energy_Used));
           }
            else if (Energy_Used <= 800 
           && Final_meter_reading >= 00000 && Final_meter_reading <= 99999 
           && Initial_meter_reading >= 00000 && Initial_meter_reading <= 99999)
          {
            Generation = ((Generation_A1)*(kWh)) + ((Rider_S)*(Energy_Used)) 
            +((Rider_B)/>/>*(Energy_Used)) + ((Rider_W)*(Energy_Used)) + ((Rider_R)
            *(Energy_Used));
}
//Winter   
   else if (Month== 12 || Month== 11 || Month== 10|| Month== 1||Month== 2|| Month== 3 
      || Month== 4 || Month== 5)      
   {
          if (Energy_Used > 800 && Final_meter_reading >= 00000
           && Final_meter_reading <= 99999 && Initial_meter_reading >= 00000 
           && Initial_meter_reading <= 99999)
          {
          Generation = ((Generation_B1)*(kWh)) + ((Generation_B2)
          *(Energy_Used - kWh))
           + ((Rider_S)*(Energy_Used)) + ((Rider_B)/>/>*(Energy_Used)) + ((Rider_W)
           *(Energy_Used)) + ((Rider_R)*(Energy_Used));
           }
            else if (Energy_Used <= 800 && Final_meter_reading >= 00000 && Final_meter_reading <= 99999 && Initial_meter_reading >= 00000 && Initial_meter_reading <= 99999)
             {
             Generation = ((Generation_B1)*(kWh)) + ((Rider_S)*(Energy_Used)) 
             +((Rider_B)/>/>*(Energy_Used)) + ((Rider_W)*(Energy_Used)) + ((Rider_R)
             *(Energy_Used));
   }
   else
   return 1;
}
                               //Late
                        
cout << "\nPlease a valid amount of days for the bill (26-35): ";
cin >> Number_of_days_in_billing_period;
    
cout << "\nPlease enter the Balance_Forward: ";
cin >> Balance_Forward;
    
Late_Penalty = 0.015;
                   
if (Number_of_days_in_billing_period >= 26
    && Number_of_days_in_billing_period <= 35)
          Late_Payment_Charge = 0;
     else if (Number_of_days_in_billing_period > 35)
     {
          Late_Payment_Charge = Balance_Forward*Late_Penalty
     *Current_Charges_Without_Tax;
     }
    else 
cout << "\nPlease enter a value withinin the 26-35 day range"
<< endl;
return 1;

//Others
    Current_Charges_Without_Tax = Distribution_Service_Charge + Generation 
    + Transmission + Fuel_Charge + Sales_and_Use_Surcharge;
    cout <<  "Current Charges Without Tax: $" << setprecision(2)
     << setiosflags(ios::fixed) << Current_Charges_Without_Tax << endl; 
    
    Total_Current_Charges = Current_Charges_Without_Tax + 
    State_and_Local_Consumption_Tax + VB_U_Tax + Late_Payment_Charge;
                
    Total_Account_Balance = Total_Current_Charges - Balance_Forward;
    Average_Daily_Cost = (Total_Current_Charges - VB_U_Tax 
    - State_and_Local_Consumption_Tax - Late_Payment_Charge)
    /Number_of_days_in_billing_period;



//Summary
system("pause");
system("CLS");
cout << "\n          Bill Summary: "
<< "\n     -------------------------\n"
<< setw(5) << "Sir/Ms. " << Name; 
if (Month== 1) //Set up for month
  cout << "\nMonth: January (Winter Rate)";
  else if (Month== 2)
       cout << "\nMonth: February (Winter Rate)";
  else if (Month== 3)
       cout << "\nMonth: March (Winter Rate)";
  else if (Month== 4)
       cout << "\nMonth: April (Winter Rate)"; 
  else if (Month== 5)
       cout << "\nMonth: May (Winter Rate)";
  else if (Month== 6)
       cout << "\nMonth: June {Summer Rate)";
  else if (Month== 7)
       cout << "\nMonth: July (Summer Rate";
  else if (Month == 8)
       cout << "\nMonth: August (Summer Rate)";
  else if (Month== 9)
       cout << "\nMonth: September (Summer Rate)";
  else if (Month== 10)
       cout << "\nMonth: October (Winter Rate)";
  else if (Month== 11)
       cout << "\nMonth: November (Winter Rate)";
  else if (Month== 12)
       cout << "\nMonth: December (Winter Rate)";
  else
  {
     cout << "\nInvalid month!"; //if user disregard
     system("pause");
     return 1;



cout << "\nBalance Forward: " << Balance_Forward
<< "\nInitial Meter Reading: " << Initial_meter_reading << " kWh"
<< "\nFinal Meter Reading: " << Final_meter_reading << " kWh"
<< "\nEnergy Used: " << Energy_Used << " kWh"
<< "\nDistribution Service Charge: $" << setprecision(2)
<<setiosflags(ios::fixed) << Distribution_Service_Charge
<< "\nElectricity Supply Service: "<< setprecision(2) 
<< setiosflags(ios::fixed)
<< "\n\tGeneration: $" << setprecision(2) << setiosflags(ios::fixed) 
<< Generation
<< "\n\tTransmission: $" << setprecision(2) << setiosflags(ios::fixed) 
<< Transmission
<< "\n\tFuel: $" << setprecision(2) << setiosflags(ios::fixed) 
<< Fuel_Charge
<< "\nSales and Use Surcharge: $" << setprecision(2) << setiosflags(ios::fixed) 
<< Sales_and_Use_Surcharge
<< "\nState/Local Consumption Tax: $" << setprecision(2) 
<< setiosflags(ios::fixed) << State_and_Local_Consumption_Tax
<< "\nVirginia Beach Utility Tax: $" << setprecision(2) 
<< setiosflags(ios::fixed) << VB_U_Tax
<< "\nLate Charge: $" << setprecision(2) << setiosflags(ios::fixed) 
<< Late_Payment_Charge
<< "\nTotal Current Charge: $" << setprecision(2) << setiosflags(ios::fixed) 
<< Total_Current_Charges
<< "\nTotal Account Balance: $" << setprecision(2) << setiosflags(ios::fixed)
<< Total_Account_Balance
<< "\nAverage Daily Charge: $" << setprecision(2) << setiosflags(ios::fixed)
<< Average_Daily_Cost << endl;


system("pause");
return 0;
}
}
}




I can't seem to figure out why the program keeps closing too early. When you get to the command where it asks for a Month the program just ends after the user inputs a value. Thanks in advance.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>