Click here to Skip to main content
15,907,001 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The issue seems to arise when the user select the regular phone bill service it doesn't give a proper output. The premium phone bill worked for me the only tricky pickle is the regular phone bill service.

What I have tried:

#include <iostream>

#include <iomanip>
//Made By Lee Rankin
/*

Write a program that calculates and prints the bill for a cell phone 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:

Regular service: $10.00 plus 50 minutes are free.  Charges for over 50 minutes are $.20 per minute.

Premium service: $25.00 plus:

a. For calls made from 6:00 a.m. to 6:00 p.m., the first 75 minutes are free; charges for over 75 minutes are $0.10 per minute.

b. For calls made from 6:00 p.m. to 6:00 a.m., the first 100 minutes are free; charges for over 100 minutes are $0.05 per minute.

Your program should prompt the user to enter an account number, a service code (type char), and the number of minutes the service was used.
A service code of R or r means regular service; a service code of P or p means premium service.  Treat any other character as an error.
Your program should output the account number, type of service, number of minutes the telephone service was used, and the amount due from the user.

For the premium service, the customer may be using the service during the day and the night.
Therefore, to calculate the bill, you must ask the user to input the number of minutes the service was used during the day and the number of minutes the service was used during the night.
*/
using namespace std;
int account_number;
float minutes;
char service;
float amount_due;
float daymin;
float nightmin;
float regular();
float premium();



int main()
{

    cout << "Enter an account number:" << endl;
    cin >> account_number;

    cout << "Enter R or r for regular service.  Enter P or p for premium service." << endl;
    cin >> service;


    //for regular accounts

 if (service == 'r' || service == 'R')
      regular();
 //for premium accounts

   else if (service == 'p' || service == 'P')
      premium();
   else
   {
     cout << "Invalid entry." << endl;
    //if user does not enter regular or premium account


   }


    //For output
    return 0;
}

float premium()
{

         cout << "Enter minutes of calls made between 6:00 a.m. to 6:00 p.m." << endl;
          cin >> daymin;
           cout << "Enter minutes of calls made between 6:00 p.m. to 6:00 a.m." << endl;
          cin >>nightmin;
if (daymin > 75)
   {
      amount_due = ((daymin - 75) * .10);
   }
   if (nightmin > 100)
   {
      amount_due = ((daymin - 100) * .05);
   }
       amount_due = amount_due + 25.00;

 cout << "Account number " <<  account_number << " with premium service.  Total minutes: " << (daymin+nightmin) << " Total Bill $" << fixed << setprecision(2) <<  amount_due << endl;


}
float regular ()
{
   cout << "Enter the number of minutes used." << endl;
   cin >> minutes;
   if (minutes <= 50.00)
   {
       amount_due = 10.00;

 cout << "Account number " << account_number << " with regular service.  Total minutes: " << minutes << " Total Bill $" << fixed << setprecision(2) <<  amount_due << endl;

   }
   else
   {
       amount_due = ((minutes -50.00) * 0.20);
cout << "Account number " << account_number << " with regular service.  Total minutes: " << minutes  << " Total Bill $" << fixed << setprecision(2) <<  amount_due << endl;

   }



}
Posted
Updated 5-Oct-17 12:53pm

Quote:
Regular service: $10.00 plus 50 minutes are free. Charges for over 50 minutes are $.20 per minute.
So you have to add $ 10 to the amount of the additional minutes:
amount_due = 10. + ((minutes -50.00) * 0.20);
Or better initialise amount_due with the base fee and add the time dependant payment:
// Regular base fee
amount_due = 10.;
if (minutes > 50)
    amount_due += (minutes - 50) * 0.2;
// Print bill here

I don't think that the premium service calculation is correct. What happens in your code when both day and night minutes are above their limits?

Do it as may second example for the regular service:
// Premium base fee
amount_due = 25.;
if (daymin > 75)
    amount_due += (minutes - 75) * 0.1;
// Similar for nightmin here
// Print bill here
 
Share this answer
 
Comments
Daszbin 5-Oct-17 9:23am    
Thank you so much your answer helped me a lot
Quote:
I have an issue with my cell phone bill project C++

When you don't understand why your code fail, it is time use debugger.

There is a tool that allow you to see what your code is doing, its name is debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900