Why wont my C++ program compile but not run?

include <cstdlib>

#include <iostream>

#include <iomanip>

using namespace std;

//Define Global Constants

const double REGULAR_SERV_CHARGES = 10.00;

const double REGULAR_RATES_OVER_50 = 0.20;

const double PREMIUM_SERV_CHARGES = 25.00;

const double PREMIUM_DAY_RATES_OVER_75 = 0.10;

const double PREMIUM_NIGHT_RATES_OVER_100 = 0.05;

const double REGULAR_FREE_MINUTES = 50.00;

const double PREMIUM_FREE_DAY_MINUTES = 75.00;

const double PREMIUM_FREE_NIGHT_MINUTES = 100.00;

// Prototype for the functions

double regularBill();

double premiumBill();

int main(int argc, char *argv[])

{

//Declare Variables

int accountNumber;

char serviceType;

double billAmount;

cout << fixed << showpoint;

cout << setprecision(2);

//Prompt the user to enter account numer

cout <<"_*_*_*_*_*_ _*_*_*_*_Sobczak National Cellphone Company_*_*_*_*_*_*_*_*_*_\n";

cout << "\nPlease enter Account Number:";

cin >> accountNumber;

cout << endl;

//Prompt the user to enter Service Type: Regular Service or Premium Service

cout << "Enter your Serivce Type: "

<< "R or r (Regular Service),"

<< "P or p (Premium Service) ";

cin >> serviceType;

cout << endl;

switch(serviceType)

{

case 'r' :

case 'R' :

billAmount = regularBill();

cout << "Account Number: "

<< accountNumber << endl;

cout << "Total Amount Due: $"

<< billAmount << endl;

break;

case 'p' :

case 'P' :

billAmount = premiumBill();

cout << "Account Number: "

<< accountNumber << endl;

cout << "Total Amount Due: $"

<< billAmount << endl;

break;

default:

cout <<"Invalid customer service type.";

exit (0);

}

return 0;

}

//Regular Service Bill Amount

double regularBill()

{

//Declare variables

int minutesUsed;

//Initial charges for regular service;

double amountDue = REGULAR_SERV_CHARGES;

//Prompt user to input number of minutes used;

cout << "Enter the number minutes used:";

cin >> minutesUsed;

//Calculate Service Charges

if ( ( minutesUsed - REGULAR_FREE_MINUTES) > 0 )

amountDue =+ REGULAR_RATES_OVER_50 * (minutesUsed - REGULAR_FREE_MINUTES);

return amountDue;

}

//Premium Sevice Bill Amount

double premiumBill()

{

//Declare Variables

int dayMinutes;

int nightMinutes;

//Initial charges for premium service:

double amountDue = PREMIUM_SERV_CHARGES;

//Prompt user to input number of daytime minutes used;

cout << "\nEnter the number of daytime minutes used (6:00 a.m. to 6:00 p.m.):";

cin >> dayMinutes;

//Prompt user to input number of nighttime minutes used;

cout <<"Enter the number of nighttime minutes used (6:00 p.m. to 6:00 a.m.)" ;

cin >> nightMinutes;

//Calculate daytime minuts charges

if ( ( dayMinutes - PREMIUM_FREE_DAY_MINUTES) > 0)

amountDue += PREMIUM_DAY_RATES_OVER_75 * (dayMinutes - PREMIUM_FREE_DAY_MINUTES);

//Calculate nighttime minuts charges

if ( ( nightMinutes - PREMIUM_FREE_NIGHT_MINUTES) > 0)

amountDue += PREMIUM_NIGHT_RATES_OVER_100 * (nightMinutes - PREMIUM_FREE_NIGHT_MINUTES);

system("PAUSE");

return amountDue;

}

1 Answer

Relevance
  • Robert
    Lv 6
    8 years ago

    Good programming ... think accountNumber and serviceType should be declared as below because most accountNumbers will be bigger than what can be handled by int:

    char accountNumber[21];

    char serviceType[2];

    ... later ...

    switch(serviceType[0])

Still have questions? Get your answers by asking now.