比较c++中的手机计划
Comparing Cell Phone Plans in C++
我在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上问的问题范围,但是我预测它很快就会被标记为离题。
相关文章:
- 如何让C++'tally up'结果并制定计划?
- 使用蓝牙组件将数据从Android手机传输到串行设备时出现问题
- 如果我的手机是 ARMv8,为什么 Android Studio 会C++编译为 ARMv7?
- C++窗口的计划问题
- 回复计划游戏结果不会显示
- 智能手机代码厨师问题逻辑混乱
- 我正在努力处理多维数组输入和输出,我管理输入,但是打印无法按计划工作
- 如何从文本文件输出数据?(学生成绩单计划)
- 为什么在此计划中,我在所有情况下都获得 0%?
- Windows 并发运行时任务计划,但有例外
- C++航班预订计划
- 如何计划在将来时间运行的操作
- 自动(toCast)显式转换是否计划在未来C++标准?
- 任务计划程序库的预处理不起作用 - 多定义错误
- GLES计划资源索引/位置与统一索引/位置
- 我应该如何使用C++创建 Google 行动行动计划履行端点?
- 多米诺骨牌计划。我不知道如何将我的矢量拉到空白中以打印出来
- C++计划持续时间内(字体)资源的分配
- 是否有任何计划将"expects"添加到 std::optional?
- 比较c++中的手机计划