In: Computer Science
Add logic to tell me to switch to unlimited if I go over $75. Use C++
/*******************************************************************************
** Program Name: Verizons Monthly Bill Calculator.
** File Name: file a03.cpp.
** Author: Natassha Quiroz
** Date: October 18, 2020 (updated 10/20/20)
** Assignment: 03
** Description: The purpose of this program is to calculate the
consumers monthly cell
** phone bill based on data usage.
** Sources: Lecture slides, lecture videos and practice programs
from lecture video.
*******************************************************************************/
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
// declaring constants.
const int PLANS = 35;
const int PLANM = 50;
const int PLANL = 70;
const int PLANU = 75;
// declaring variables.
char planchoice;
double total = 0.0, data = 0.0;
//This while will continue to prompt the question until the user
enters a valid response.
while (true)
{
// displaying the menu
cout << "S = Plan A" << endl;
cout << "M = Plan B" << endl;
cout << "L = Plan C" << endl;
cout << "U = Plan unlimited" << endl;
// getting the plan plan choice entered by the user
cout << "Which one of these plans do you have? ";
cin >> planchoice;
// Checking whether the user entered a valid plan choice
if (planchoice != 'S' && planchoice != 's' &&
planchoice != 'M'
&& planchoice != 'm' && planchoice != 'L'
&& planchoice != 'l' && planchoice != 'U'
&& planchoice != 'u')
{
cout << "** Invalid Plan Choice **" << endl;
}
else
break;
}
// getting the choice entered by the user
cout << "How many GB have you used so far? ";
cin >> data;
data = ceil(data);
// Based on the user plan choice the corresponding case will be
executed
switch (planchoice)
{
case 'S':
case 's':
{
if (data <= 2)
{
total = PLANS;
}
else
{
total = PLANS;
for (int i = 1; i <= data - 2; i++)
{
total += 15;
}
}
break;
}
case 'M':
case 'm':
{
if (data <= 2)
{
total = PLANM;
}
else
{
total = PLANM;
for (int i = 1; i <= data - 2; i++)
{
total += 15;
}
}
break;
}
case 'L':
case 'l':
{
if (data <= 2)
{
total = PLANL;
}
else
{
total = PLANL;
for (int i = 1; i <= data - 2; i++)
{
total += 15;
}
}
break;
}
case 'U':
case 'u':
{
total = PLANU;
break;
}
}
// display the customers total charge
cout << "Total Charges :$" << total << endl;
return 0;
}
Hello! :)
Here is the updated code:
a03.cpp:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    // declaring constants.
    const int PLANS = 35;
    const int PLANM = 50;
    const int PLANL = 70;
    const int PLANU = 75;
    // declaring variables.
    char planchoice;
    double total = 0.0, data = 0.0;
    //This while will continue to prompt the question until the user enters a valid response.
    while (true)
    {
        // displaying the menu
        cout << "S = Plan A" << endl;
        cout << "M = Plan B" << endl;
        cout << "L = Plan C" << endl;
        cout << "U = Plan unlimited" << endl;
        // getting the plan plan choice entered by the user
        cout << "Which one of these plans do you have? ";
        cin >> planchoice;
        // Checking whether the user entered a valid plan choice
        if (planchoice != 'S' && planchoice != 's' && planchoice != 'M'
            && planchoice != 'm' && planchoice != 'L'
            && planchoice != 'l' && planchoice != 'U' && planchoice != 'u')
        {
            cout << "** Invalid Plan Choice **" << endl;
        }
        else
            break;
    }
    // getting the choice entered by the user
    cout << "How many GB have you used so far? ";
    cin >> data;
    data = ceil(data);
    // Based on the user plan choice the corresponding case will be executed
    switch (planchoice)
    {
        case 'S':
        case 's':
        {
            if (data <= 2)
            {
                total = PLANS;
            }
            else
            {
                total = PLANS;
                for (int i = 1; i <= data - 2; i++)
                {
                    total += 15;
                }
            }
            break;
        }
        case 'M':
        case 'm':
        {
            if (data <= 2)
            {
                total = PLANM;
            }
            else
            {
                total = PLANM;
                for (int i = 1; i <= data - 2; i++)
                {
                    total += 15;
                }
            }
            break;
        }
        case 'L':
        case 'l':
        {
            if (data <= 2)
            {
                total = PLANL;
            }
            else
            {
                total = PLANL;
                for (int i = 1; i <= data - 2; i++)
                {
                    total += 15;
                }
            }
            break;
        }
        case 'U':
        case 'u':
        {
            total = PLANU;
            break;
        }
    }
    // display the customers total charge
    cout << "Total Charges :$" << total << endl;
    // to tell the user to switch to unlimited if the total goes over $75
    if (total > 75)
    {
        cout << "Please switch to unlimited."  << endl;
    }
    return 0;
}
Here is a snapshot of a demo run:

Hope this helps! :)