Question

I cannot for the life of me figure out how to calculate a certain part of my program. I just need some help in how you would go about coming to the correct totals.

In File

111111 M 303-333-3333 333 550 0.9 720-777-7777 501 444 0.4

222222 U 303-444-5555 555 55 3.3

333333 H 720-888-9999 1888 888 3.3 720-999-1111 999 1050 1.8 720-222-2222 800 800 2.1

444444 L 720-123-4567 88 10 0

Using that that from a text file and knowing this..

Phone charges (as defined below) for each cell phone

State and local taxes of 8.1% tax on phone charges Note: 8.1% would be stored as 0.081

$ 1.44 Universal Service fee per phone

L = Low usage plan (no minutes included) 
M = Mid usage plan (500 talk minutes and 500 texts included) 
H = High usage plan (1000 talk minutes and 1000 texts and 2 GB data included) 
U = Unlimited plan 

Phone charges are as follows for each plan: 
Plan Base Fee Charge for minutes Charge for texts Charge for data 

L* 4.99 0.10 per minute 0.10 per text Data not available 

M 49.99 0.08 per minute over 500 0.08 per text over 500 $2.88 per 500 MB over 500 MB 

H 74.99 0.07 per minute over 1000 0.07 per text over 1000 $1.78 per 500 MB over 2 GB 

U 99.99 No charge No charge No charge 

I need to somehow get to these results through calculations

111111 Mid usage 2 $ 118.48 

222222 Unlimited 1 $ 109.53 

333333 High usage 3 $ 326.19 

444444 Low usage 1 $ 17.43 

Month's Total $ 571.63

I just need help mainly with the 1st and 3rd accounts on file. So far all I have is this (for the mid and high plan charges)..

float midPlanCharge (int& min, int& texts, float& data)
{
float total;


// double check!!!!!!!!!!!!!!!!!!!
if ( min <= BASE_MID_MIN && texts <= BASE_MID_TEXT && data <= BASE_MID_DATA )
{
    total = MID_FEE;
}
else if ( min > BASE_MID_MIN && texts <= BASE_MID_TEXT && data <= BASE_MID_DATA )
{
    total = MID_FEE + ( (min - BASE_MID_MIN) * MID_MIN );
}
else if ( min <= BASE_MID_MIN && texts > BASE_MID_TEXT && data <= BASE_MID_DATA )
{
    total = MID_FEE + ( ( texts - BASE_MID_TEXT) * MID_TEXT);
}
else if ( min <= BASE_MID_MIN && texts <= BASE_MID_TEXT && data > BASE_MID_DATA )
{
    total = MID_FEE + ( (( data - BASE_MID_DATA) * 1000 ) * MID_DATA);
}
else if ( min > BASE_MID_MIN && texts <= BASE_MID_TEXT && data > BASE_MID_DATA )
{
    total = MID_FEE + (( min - BASE_MID_MIN) * MID_MIN) + ( (( data - BASE_MID_DATA)*1000) * MID_DATA);
}
else if ( min > BASE_MID_MIN && texts > BASE_MID_TEXT && data <= BASE_MID_DATA )
{
    total = MID_FEE + ((min - BASE_MID_MIN) * MID_MIN) + (( texts - BASE_MID_TEXT) * MID_TEXT);
}
else if ( min <= BASE_MID_MIN && texts > BASE_MID_TEXT && data > BASE_MID_DATA )
{
    total = MID_FEE + ((texts - BASE_MID_TEXT) * MID_TEXT) + (((data - BASE_MID_DATA)*1000) * MID_DATA);
}
else {
    total = MID_FEE + ((min - BASE_MID_MIN) * MID_MIN) + ((texts - BASE_MID_TEXT) * MID_TEXT) + (((data - BASE_MID_DATA)*1000) * MID_DATA);
}


return total;
}

float highPlanCharge (int& min, int& texts, float& data)
{
float total;

if ( min <= BASE_HIGH_MIN && texts <= BASE_HIGH_TEXT && data <= BASE_HIGH_DATA )
{
    total = HIGH_FEE;
}
else if ( min > BASE_HIGH_MIN && texts <= BASE_HIGH_TEXT && data <= BASE_HIGH_DATA )
{
    total = HIGH_FEE + ( (min - BASE_HIGH_MIN) * HIGH_MIN );
}
else if ( min <= BASE_HIGH_MIN && texts > BASE_HIGH_TEXT && data <= BASE_HIGH_DATA )
{
    total = HIGH_FEE + ( ( texts - BASE_HIGH_TEXT) * HIGH_TEXT);
}
else if ( min <= BASE_HIGH_MIN && texts <= BASE_HIGH_TEXT && data > BASE_HIGH_DATA )
{
    total = HIGH_FEE + ((( data - BASE_HIGH_DATA) * 1000) * HIGH_DATA);
}
else if ( min > BASE_HIGH_MIN && texts <= BASE_HIGH_TEXT && data > BASE_HIGH_DATA )
{
    total = HIGH_FEE + (( min - BASE_HIGH_MIN) * HIGH_MIN) + ((( data - BASE_HIGH_DATA)*1000) * HIGH_DATA);
}
else if ( min > BASE_HIGH_MIN && texts > BASE_HIGH_TEXT && data <= BASE_HIGH_DATA )
{
    total = HIGH_FEE + ((min - BASE_HIGH_MIN) * HIGH_MIN) + (( texts - BASE_HIGH_TEXT) * HIGH_TEXT);
}
else if ( min <= BASE_HIGH_MIN && texts > BASE_HIGH_TEXT && data > BASE_HIGH_DATA )
{
    total = HIGH_FEE + ((texts - BASE_HIGH_TEXT) * HIGH_TEXT) + (((data - BASE_HIGH_DATA)*1000) * HIGH_DATA);
}
else {
    total = HIGH_FEE + ((min - BASE_HIGH_MIN) * HIGH_MIN) + ((texts - BASE_HIGH_TEXT) * HIGH_TEXT) + (((data - BASE_HIGH_DATA)*1000) * HIGH_DATA);
}
return total;
}
Was it helpful?

Solution

(1) Not sure if you were told to work with floats but they are a pain to use for money because of the internal rounding. You are better off using an integer and working in pennies and just dividing and multiplying by 100 when you have to - usually when you need to print the values.

(2) I just did your mid-range as an example and it seems to work and, if not, it should be close enough for you to correct.

(3) The two you are stuck on (1 & 3) have multiple phones so presumably you are parsing that in the beginning. I just simulated it here. This won't get you home free but hopefully reduces the confusion - some of which seemed to be of your own making.

#include <iostream>
#include <cmath>

using namespace std;

const float SERVICE_FEE = 1.44;

const float MID_FEE = 49.99;
const int   BASE_MID_MIN = 500;
const float MID_MIN = 0.08;
const int   BASE_MID_TEXT = 500;
const float MID_TEXT = 0.08;
const int   BASE_MID_DATA = 500;
const float MID_DATA = 2.88;

float midPlanCharge (int min, int texts, float data)
{
    float total = MID_FEE;

    data *= 1000;

    if (min > BASE_MID_MIN)
        total += (min - BASE_MID_MIN) * MID_MIN;

    if (texts > BASE_MID_TEXT)
        total += (texts - BASE_MID_TEXT) * MID_TEXT;

    if (data > BASE_MID_DATA)
        total += roundf((data - BASE_MID_DATA) / BASE_MID_DATA) * MID_DATA;

    return total;
}

int main(int argc, char *argv[])
{
    float accTotal = 0.0;

    accTotal += midPlanCharge(333, 550, 0.9);
    accTotal += midPlanCharge(501, 444, 0.4);

    accTotal += (accTotal * 0.081);  //tax
    accTotal += SERVICE_FEE * 2;     //service fee on 2 phones

    cout << "Total = " << accTotal << endl;

    return(0);
}

Output : Total = 118.482

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top