3 Replies - 5545 Views - Last Post: 05 March 2011 - 03:08 PM Rate Topic: -----

#1 efremcowper  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 13
  • Joined: 19-July 10

This program should calcutates a nd print the bill for a cell phone co

Posted 05 March 2011 - 12:00 PM

/*

Write a program that calculates and prints the bill for a cellular telephone company. The company offers two types of service: regular and premium. Its rates vary, depending on the type of service. The rates are computed as follows:


*/
#include<iostream>

#include<iomanip>

 using namespace std;



// Function prototypes

 double calculateRegularBill(int);

 double calculatePremiumBill(int, int);

 void   displayCharges(char, double);



 int main()

 {

    double minuteservice,minuteserviceday,minuteservicenight;

     double daycharge =0.0, nightcharge =0.0;

     char servicecode, again;

    double charges;





//Format the output

    cout<< setprecision(2) << fixed;




 //Ask for user input

  do

   {



       cout << "Enter service code r (Regular Service) or p (Premium Service):\n";

        cin >> servicecode;

           while (servicecode != 'r' && servicecode != 'R' && servicecode != 'p' && servicecode != 'P')
                {

               cout << "Your service code is invalid. \n";

                }

                cout << "Do you want another input ? (y/n)\n";
                cin >> again;

                    if (again == 'n')

                    {

                     cout << "Thank you \n";
                     return 0;
                   }





     switch(servicecode)

     {case 'r':

     case 'R':

                    calculateRegularBill;
                break;







      case 'p':

       case 'P':

                    calculatePremiumBill;

                   break;




        default: cout << "Your service code is invalid.";



      } //end case


 } while (again == 'Y' || again == 'y');

return 0;

 }//end main





 // This function calculate Regular service

 double calculateRegularBill(int minuteservice, double regularcharge)

 {

    cout << "Enter the number of minutes the telephone service is used: \n";

                   cin >> minuteservice;

                  if (minuteservice <= 50)
                     {

                     regularcharge = 10;

                     }

                    else if (minuteservice > 50)

                     {

                   regularcharge = 10 + (minuteservice - 50) * .20;

                    }

    return 0;

 }



 // This function calculate Premium service

double calculatePremiumBill(int serviceminuteday, int serviceminutenight);



       cout << "Enter the number of minutes the telephone service was used during the day: If the service is not used, enter 0: \n";
      cin >> minuteserviceday;

        cout << "Enter the number of minutes the telephone service was used during the night: If the service is not used, enter 0: \n";
       cin >> minuteservicenight;

                   if (minuteserviceday <= 75)

                    {

                     daycharge = 0;

                     }
                     else if (minuteserviceday > 75)

                    {

                    daycharge = (minuteserviceday - 75) * .10;

                    }

                  if (minuteservicenight <= 100)
                    {
                    nightcharge = 0;

                    }

                    else if (minuteservicenight > 100)

                    {

                     nightcharge = (minuteservicenight - 100) * .05;

                     }



                    minuteservice = minuteserviceday + minuteservicenight;

                     charges = daycharge + nightcharge + 25;

    }




// This function displays the type of service and the service charge.

 void displayCharges(char s, double charges)

 {

    cout << "Type of Service: \n"; << servicecode << endl;
     cout << "Service charges: " << calculateRegularBill << endl;

         cout << "Service charges: " << calculatePremiumBill << endl;


MOD EDIT: Fixed code tags...here's how you use them:

:code:

This post has been edited by JackOfAllTrades: 05 March 2011 - 01:14 PM


Is This A Good Question/Topic? 0
  • +

Replies To: This program should calcutates a nd print the bill for a cell phone co

#2 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 615
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: This program should calcutates a nd print the bill for a cell phone co

Posted 05 March 2011 - 12:23 PM

Please use code tags.

Aside from that, what's the problem??
Was This Post Helpful? 0
  • +
  • -

#3 efremcowper  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 13
  • Joined: 19-July 10

Re: This program should calcutates a nd print the bill for a cell phone co

Posted 05 March 2011 - 02:55 PM

Your program should print the account number, type of service, minutes used, (if service type is premium, print both the daytime minutes used and evening minutes used, and the total amount due. can someone please help me.

#include <iostream>
#include <iomanip>

using namespace std;
int main()
 {



    const double REG_CHARGES = 10.00;
    const int REG_MINUTES = 50;
    const double REG_RATE_OVER_50 = 0.20;
    const double PREM_SERV_CHARGES = 25.00;
    const int PREM_FREE_DAY_MINUTES = 75;
    const double PREM_DAY_RATE_OVER_75 = 0.10;
    const int PREM_FREE_NIGHT_MINUTES = 100;
    const double PREM_NIGHT_RATE_OVER_100 = 0.05;
    double regularServiceFee;
    //double premium;
    int account;
    char service_type;
    double amount_due;
    int minutes;

    cout << "Enter Account Number" << endl;
    cin >> account;
    cout << "Enter Service Type: "
    << "R or r (Regular Service), "
    << "P or p (Premium Service): ";
    cin >> service_type;
    cout << "Enter the minutes used:" << endl;
    cin>> minutes;

    switch (service_type)
    {
        case 'r':
        case 'R':



       case 'p':
       case 'P':



        break;

       default:
       cout << "Invalid customer type."
        << endl;
    }
    if ( minutes<= REG_MINUTES)
    {
          minutes=REG_MINUTES;
    }
    else if (minutes > REG_MINUTES)
    {
        regularServiceFee= REG_MINUTES * .20;
    }


    if (minutes <= PREM_FREE_DAY_MINUTES)
    {
        amount_due = 0;
    }
    else if (minutes > PREM_FREE_DAY_MINUTES)
    {
        amount_due= (minutes - PREM_FREE_DAY_MINUTES) * PREM_DAY_RATE_OVER_75;

    }
    if (minutes <= PREM_FREE_NIGHT_MINUTES)
    {
        amount_due = 0;
    }
    else if (minutes >PREM_FREE_NIGHT_MINUTES )
    {
        amount_due = ( PREM_SERV_CHARGES - PREM_FREE_NIGHT_MINUTES) * PREM_NIGHT_RATE_OVER_100 ;


        amount_due = PREM_DAY_RATE_OVER_75 + PREM_NIGHT_RATE_OVER_100;
        amount_due = PREM_FREE_DAY_MINUTES  +PREM_FREE_NIGHT_MINUTES+ PREM_SERV_CHARGES;

     }
        cout << fixed << showpoint;
        cout << setprecision(2);
         cout << " Account Number = "
        << account << endl;
       cout << " The regular minutes used is " << REG_MINUTES << endl;
        cout <<" The day minutes used is " << PREM_FREE_DAY_MINUTES << endl;
        cout <<" The  night minutes used is " << PREM_FREE_NIGHT_MINUTES << endl;
        cout << "Amount Due = $"
        << amount_due << endl;
        //default:
          cout << "Invalid customer type."
        << endl;


        return 0;
 }



This post has been edited by JackOfAllTrades: 05 March 2011 - 03:06 PM

Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6078
  • View blog
  • Posts: 23,548
  • Joined: 23-August 08

Re: This program should calcutates a nd print the bill for a cell phone co

Posted 05 March 2011 - 03:08 PM

Merged duplicate topics. DO NOT create a new topic when you already have one!!!!

Also, I have serious doubts about your ability to pass a programming class, seeing as you cannot even seem to figure out how to USE CODE TAGS properly! It's NOT ROCKET SURGERY!

:code:

If that's too complicated for you, read the first link in my signature.

Thirdly, read this.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1