C++ 如何使用C++;
对于课堂项目,我必须开发一个计算移动设备服务成本的程序。有3个软件包供用户选择。服务的成本由基本价格和要使用的消息单元的数量决定。在用户选择一个软件包后,我必须让他们知道软件包的价格,同时让他们知道其他软件包是否更便宜,并使用switch语句显示价格的差异。我已经写了一些比较软件包的switch语句,但是如果有比所选软件包更便宜的软件包,我如何显示和计算它们将节省多少呢?我也是一个初学者,所以放松点C++ 如何使用C++;,c++,switch-statement,C++,Switch Statement,对于课堂项目,我必须开发一个计算移动设备服务成本的程序。有3个软件包供用户选择。服务的成本由基本价格和要使用的消息单元的数量决定。在用户选择一个软件包后,我必须让他们知道软件包的价格,同时让他们知道其他软件包是否更便宜,并使用switch语句显示价格的差异。我已经写了一些比较软件包的switch语句,但是如果有比所选软件包更便宜的软件包,我如何显示和计算它们将节省多少呢?我也是一个初学者,所以放松点 int main() { bool finished = false; do
int main() {
bool finished = false;
do {
// to keep it simple
double choice_a = 9.95;
double choice_b = 19.95;
double choice_c = 39.95;
char choice;
int message_units;
double price;
bool selected = false;
// this loop shows the options initially
do {
cout << "Which package do you choose (enter A, B or C)" << endl;
// you will need to check this
cin >> choice;
// keeping it simple
if (choice == 'A') { price = choice_a; selected = true; }
else if (choice == 'B') { price = choice_b; selected = true; }
else if (choice == 'C') { price = choice_c; selected = true; }
cout << endl;
}
// loops until something was selected
while (selected == false);
// user enters how many units is wanted
cout << "How many message units (enter 1 - 672)" << endl;
// again check this (if homework requires checking input)
cin >> message_units;
// Calculating message units
if(message_units > 5){
price += 100 * (message_units - 5);
}
if(message_units > 15){
price += 50 * (message_units - 15);
}
// Total Price Output
cout << "Your total cost is " << price/100 << endl
// Is user done?
char done;
cout << "Do you want to enter another? press enter to continue.
cin >> done;
// check
if (done != ' ') {
finished = true;
}
}
while (finished = false);
}
switch (choice)
{
case 'A':
if(choice_b < choice_a);
cout << "You can save by switching to package B" << endl;
else if(choice_c < choice_a);
cout << "You can save by switching to package C" << endl;
break;
case 'B':
if(choice_a < choice_b);
cout << "You can save by switching to package A" << endl;
else if(choice_c < choice_b);
cout << "You can save by switching to package C" << endl;
break;
case 'C':
if(choice_a < choice_c);
cout << "You can save by switching to package A" << endl;
else if(choice_b < choice_c);
cout << "You can save by switching to package B" << endl;
break;
}
intmain(){
bool finished=false;
做{
//保持简单
双重选择a=9.95;
双向选择b=19.95;
双重选择c=39.95;
字符选择;
int消息单元;
双倍价格;
bool selected=false;
//此循环最初显示选项
做{
不能选择;
//保持简单
如果(choice='A'){price=choice\u A;selected=true;}
else if(choice='B'){price=choice_B;selected=true;}
else if(choice='C'){price=choice\u C;selected=true;}
法庭(5){
价格+=100*(信息单位-5);
}
如果(信息单位>15){
价格+=50*(信息单位-15);
}
//总价格产出
cout假设你用相同的数量比较这两者
节省=[(选择价格)-(更便宜的选择价格)]×数量
如果您进行此计算,并将其分配给名为Savings的double类型,则可以将其打印出来
cout假设你用相同的数量比较这两者
节省=[(选择价格)-(更便宜的选择价格)]×数量
如果您进行此计算,并将其分配给名为Savings的double类型,则可以将其打印出来
不能包含
使用名称空间std;
int main(){
bool finished=false;
字符选择;
双重选择a=9.95;
双向选择b=19.95;
双重选择c=39.95;
int消息单元;
双倍价格;
bool selected=false;
做{
//保持简单
//此循环最初显示选项
做{
不能选择;
//保持简单
如果(choice='A'){price=choice\u A;selected=true;}
else if(choice='B'){price=choice_B;selected=true;}
else if(choice='C'){price=choice\u C;selected=true;}
法庭(5){
价格+=100*(信息单位-5);
}
如果(信息单位>15){
价格+=50*(信息单位-15);
}
//总价格产出
不能包含
使用名称空间std;
int main(){
bool finished=false;
字符选择;
双重选择a=9.95;
双向选择b=19.95;
双重选择c=39.95;
int消息单元;
双倍价格;
bool selected=false;
做{
//保持简单
//此循环最初显示选项
做{
不能选择;
//保持简单
如果(choice='A'){price=choice\u A;selected=true;}
else if(choice='B'){price=choice_B;selected=true;}
else if(choice='C'){price=choice\u C;selected=true;}
法庭(5){
价格+=100*(信息单位-5);
}
如果(信息单位>15){
价格+=50*(信息单位-15);
}
//总价格产出
如果OP说他们是初学者,那么如果你详细解释你的答案,而不是仅仅发布解决问题的代码,这对学习过程可能会很有用。@Thank伙计,你们是因为帮助而获得报酬还是因为你们那么喜欢编程?因为我喜欢编程,也喜欢帮助别人:)好的,我的计算信息单位是多少我的代码的第节仍然没有给我正确的输出。当我运行它时,小数点不在正确的位置。对于我的项目,如果输入的消息单元超过5个,我必须在包A中添加每个消息单元1.00。如果输入的消息单元超过15个,我还必须在包B中添加每个消息单元0.50。鉴于OP声明它们是一个开始呃,如果你详细解释你的答案,而不是仅仅发布解决问题的代码,这可能对学习过程很有用。@Thank伙计,你们是因为帮助而获得报酬还是因为你们那么喜欢编程?都是因为我喜欢编程和帮助人:)好的,我代码中的“计算消息单位”部分仍然没有给我t输出正确。当我运行它时,小数点不在正确的位置。对于我的项目,如果输入的消息单元超过5个,我必须在A包中添加每个消息单元1.00。如果输入的消息单元超过15个,我还必须在B包中添加每个消息单元0.50。鉴于OP声明他们是初学者,这可能对学习专业人士有用如果你详细解释了你的答案,而不是仅仅发布解决问题的代码,那就可以了。@Thank伙计,你们是因为帮助而获得报酬呢,还是因为你们那么喜欢编程?都是因为我喜欢编程和帮助别人:)好的,我的代码中的“计算消息单位”部分仍然没有给出正确的输出。小数点不在当我运行它时,正确的位置。对于我的项目,如果输入的消息单位超过五个,我必须在A包中添加每个消息单位1.00。如果输入的消息单位超过15个,我还必须在B包中添加每个消息单位0.50。我的公式应该是什么样的,因为当我输出价格时小数点不正确?它不起作用。对于我的如果输入的邮件单元超过五个,则项目I必须为包A添加每个邮件单元1.00。此外,I ha
// Calculating message units
if(message_units > 5){
price += 100 * (message_units - 5);
}
if(message_units > 15){
price += 50 * (message_units - 15);
}
double Total_Cost;
if(message_units => 5 && message_units<15){
Total_Cost = price * (message_units - 5);
}
else if(message_units => 15){
Total_Cost = price * (message_units - 15);
}
else{
Total_Cost = price * message_units;
}
#include <iostream>
using namespace std;
int main() {
bool finished = false;
char choice;
double choice_a = 9.95;
double choice_b = 19.95;
double choice_c = 39.95;
int message_units;
double price;
bool selected = false;
do {
// to keep it simple
// this loop shows the options initially
do {
cout << "Which package do you choose (enter A, B or C)" << endl;
// you will need to check this
cin >> choice;
// keeping it simple
if (choice == 'A') { price = choice_a; selected = true; }
else if (choice == 'B') { price = choice_b; selected = true; }
else if (choice == 'C') { price = choice_c; selected = true; }
cout << endl;
}
// loops until something was selected
while (selected == false);
// user enters how many units is wanted
cout << "How many message units (enter 1 - 672)" << endl;
// again check this (if homework requires checking input)
cin >> message_units;
// Calculating message units
if(message_units > 5){
price += 100 * (message_units - 5);
}
if(message_units > 15){
price += 50 * (message_units - 15);
}
// Total Price Output
cout << "Your total cost is " << price/100 << endl;
switch (choice)
{
case 'A':
if(choice_b < choice_a)
cout << "you can save by switching to package B it saves: " << choice_a - choice_b << " if you choose B" << endl;
else if(choice_c < choice_a)
cout << "You can save by switching to package C is saves: " << choice_a - choice_c << endl;
break;
case 'B':
if(choice_a < choice_b)
cout << "you can save by switching to package A it saves: " << choice_b - choice_a << " if you choose a" << endl;
else if(choice_c < choice_b)
cout << "you can save by switching to package C it saves: " << choice_b - choice_c << " if you choose c" << endl;
break;
case 'C':
if(choice_a < choice_c)
cout << "you can save by switching to package A it saves: " << choice_c - choice_a << " if you choose a" << endl;
else if(choice_b < choice_c)
cout << "you can save by switching to package A it saves: " << choice_c - choice_b << " if you choose b" << endl;
break;
}
// Is user done?
char done;
cout << "Do you want to enter another? press enter to continue.";
cin >> done;
// check
if (done != ' ') {
finished = true;
}
}
while (finished == false);
}