Question

In: Computer Science

Add logic to tell me to switch to unlimited if I go over $75. Use C++...

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;
}

Solutions

Expert Solution

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! :)


Related Solutions

hi,I have this C++ program,can someone add few comments with explanation what is the logic and...
hi,I have this C++ program,can someone add few comments with explanation what is the logic and what is what?thank you I m total beginner #include <iostream> using namespace std; int ArraySum(int MyArray[], int size){ int* p = MyArray; int sum = 0; while(p<MyArray+size){ sum += *p; p++; } return sum; } int main() { int MyArray[10] = {4, 0, 453, 1029, 44, 67, 111, 887, 4003, 1002}; cout<<ArraySum(MyArray,10); return 0; }
please show me or tell me a trick, on how can i tell right away when...
please show me or tell me a trick, on how can i tell right away when a characteristics equation(system) is 1)overdamped 2)underdamped 3)critically damped 4) nonlinear show each an example write neatly!!!!!
Can anyone please tell me what function in excel I could use in this instance: I...
Can anyone please tell me what function in excel I could use in this instance: I have two spreadsheets with sales of products for a company. I am needing to create a new spreadsheet with gross sales by month and by region. It haven't included all the worksheets, because I truly just need pointed in the right direction.
Hello, for c++, please expert tell me how to use unordered set to do the rest...
Hello, for c++, please expert tell me how to use unordered set to do the rest method:insert, remove, find in container, declaration, visiting all elements.
For each of the following items, tell me where they would go on a balance sheet...
For each of the following items, tell me where they would go on a balance sheet or that they would not go on a balance sheet. I want the name of the line on the balance sheet and the section (i.e. accounts payable in current liabilities). You buy fertilizer in December to use the next spring. The fertilizer will not be delivered until it is used. The costs associated with planting winter wheat. You sold hay to a neighbor, but...
Could you please tell me what it is?use what theroy? Rather than exporting or FDI I...
Could you please tell me what it is?use what theroy? Rather than exporting or FDI I can negotiate a contract that gives another company the right to make my product in their country.This is known as: When an immigrant sends money to his or her family back in their home country. (it’s difficult to measure) When more expensive goods sourced from inside a customs union replace the consumption of less expensive goods from outside the customs union. A situation in...
Go to the discussion room and tell me what form of business ownership you have chosen...
Go to the discussion room and tell me what form of business ownership you have chosen for your imaginary business. You must tell me why you chose that form of ownership, listing two or three of the advantages of that form of ownership, and also listing two or three of the disadvantages of that form of ownership. You must then describe one of the forms of business ownership that you did NOT choose for your business, and tell me why...
Hello, I was wondering if you could tell me how to do a general Ledger? I...
Hello, I was wondering if you could tell me how to do a general Ledger? I just finish doing a Sales Journal, Purchase Journal, Cash Receipt Journal, Cash Disbursements Journal and a General Journal under one company Sound Bytes Electronics). What I wanted to know is do I use the General Journal to do the General Ledger? Or do I use the Special Journals and the General Journal to do the General Ledger? Can you put me in the right...
I need a speech to give me a girlfriend. I want to tell her how much...
I need a speech to give me a girlfriend. I want to tell her how much I love her and how much she means to me. I want to tell her that she is the only thing I think of from morning till night. Her name is Angie. she is the most beautiful girl I have ever met and I need something like a paragraph to show how much I love her. I want it so sweet and loving that...
For Networks -> Please tell me about the following: Why are CRCs used over checksums in...
For Networks -> Please tell me about the following: Why are CRCs used over checksums in many cases? What is a sliding window protocol? How does the Go-Back-N sliding window work? How does the Selective Repeat sliding window work? What is PPP?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT