比较c++中的手机计划

Comparing Cell Phone Plans in C++

本文关键字:手机 计划 c++ 比较      更新时间:2023-10-16

我在c++入门。我的任务是写一个像员工终端一样的程序。程序应该提示客户他们在哪个计划上(A、B或C),程序应该识别大小写字母。然后提示他们的数据使用情况。方案A是15美元,有200mb的流量,每增加mb额外收费0.06美元。方案B是25美元,有2000mb的流量,每增加mb额外收费0.02美元。方案C是无限制的。

我已经算出来了。我最纠结的部分是比较。如果一个人的计划,让说,他们使用超过367 mb(25.02美元),但小于784 mb(50.04美元),它告诉他们他们会节省多少如果他们转向B计划。如果他们使用367 mb以上就必须告诉他们多少他们会保存在计划我也要做相同的人B计划去那边的日期只有他们超龄总数超过C计划,因此价格会省钱他们在计划C .

程序不需要建议降级计划(即从计划C移到计划A),只需要升级。

#include <iostream>
using namespace std;
/* Project One
 Wriitten by A-R
*/
int main ()
{  
    char    Plan_omega;
    int     MB;
    double  Plan_Cost_A, Plan_Cost_B, Plan_Cost_C, Variation_A;
    cout << "Which plan does the customer currently have?"<< endl;                           // Input of the customer's current plan.
    cin  >>  Plan_omega;
    while ( !(Plan_omega=='A') && !(Plan_omega=='B') && !(Plan_omega=='C') &&   // Must input either A, B, or C (upper of lower case) or it will reprompt.
            !(Plan_omega=='a') && !(Plan_omega=='b') && !(Plan_omega=='c') ) {
        cout << "Please enter only A, B, or C" << endl;
        cin  >>  Plan_omega; 
    }
    cout << "How many MB did the customer use last month?" <<endl;  
    cin  >> MB;
    while ( MB < 0 || MB > 10000) {
        cout << "Please enter a value between 0 and 10,000" << endl;
        cin  >>  MB; 
    }
    switch (Plan_omega){
        case 'A':
        case 'a':
        cout << "The customer's total bill is $"; 
            if (MB > 200) {
                Plan_Cost_A = 15 + ((MB - 200) * 0.06);
            } else {
                Plan_Cost_A = 15;
            }
            cout << Plan_Cost_A <<endl;
            break;
        case 'B':
        case 'b':
        cout << "The customer's total bill is $";     
            if (MB > 2000){
                Plan_Cost_B = 25 + ((MB - 2000) * 0.02);
            } else {
                Plan_Cost_B = 25;
            }
            cout << Plan_Cost_B <<endl;
            break;
        cout << "The customer's total bill is $";    
        case 'C':
        case 'c':
        cout << "The customer's total bill is $";     
            if (MB > -1){
                Plan_Cost_C = 50;
            } else {
                Plan_Cost_C = 50;
            cout << Plan_Cost_C <<endl;
            }
            break;


    }
    return 0; 
}    

谢谢你的帮助。上次我写了一个更简短的问题,每个人都问我更多的信息。我试着保持简短,但我失败了。

而且,我知道有很多方法可以使这个程序变小或添加快捷方式。我的老师特别要求程序的制作方式要和我的程序类似,再次感谢。

您可以设置一个if...elseif块来比较MB与367和748的值,并使用它来确定是否应该显示与其他计划的比较。

的例子:

int main (void)
{    
    char Plan_omega;
    int MB;
    //get the value of Plan_omega and MB
    //Calculate Plan_Cost_A, Plan_Cost_B, and Plan_Cost_C
    switch (Plan_omega){
        //code here to display their current bill
    }
    if (MB > 367 && MB < 748) {
        // Calculate what they would have saved on Plan B
    }
    elseif (MB > 367) {
        // Calculate what they would have saved on Plan C
    }
    return 0; 
}

我觉得这个问题不属于你可以在Stack Overflow上问的问题范围,但是我预测它很快就会被标记为离题。