如何让C++'tally up'结果并制定计划?
How can I get C++ to 'tally up' the results and produce a plan?
我正在做一个练习,我必须编写一个程序,该程序将根据用户对一系列是或否问题的回答来建议订阅计划。
该练习基于以下图表: https://i.stack.imgur.com/W2fL0.jpg
这是我的代码,所以你可以看到我到目前为止做了什么......
// Firstly, Welcome the client!
cout << " Welcome to the Wordpress subsciption sugesstion Tool!" << endl;
cout << " In order to find the right plan for you, we'll need to ask you a series of questions!" << endl;
cout << " Answer the following questions using 'y' or 'n' keys when prompted." << endl;
// secondly, Present the series of questions and prompt the user for input.
cout << 1.) Would you like to utilize free themes? (y/n)" << endl;
cin >> answer;
if(answer = 'y')
{
freeTheme = true;
}
else
{
freeTheme = false;
}
cout << "tn 2.) Would you like to customize your themes? (y/n)" << endl;
cin >> answer;
if(answer = 'y')
{
customDesign = true;
}
else
{
customDesign = false;
}
cout << "tn 3.) Will you be needing Search Engine Optimization? (y/n)" << endl;
cin >> answer;
if(answer = 'y')
{
seoTools = true;
}
else
{
seoTools = false;
}
cout << "tn 4.) Is live support important for you? (y/n)" << endl;
cin >> answer;
if(answer = 'y')
{
liveSupport = true;
}
else
{
liveSupport = false;
}
cout << "tn 5.) How much data will you need to host? 3GB, 6GB, 13GB, or unlimited(999GB)?" << endl;
cin >> storageCapacity;
if(storageCapacity = 3)
{
costPerMonth = 0.00;
}
else if (storageCapacity = 6)
{
costPerMonth = 5.00;
}
else if (storageCapacity = 13)
{
costPerMonth = 8.00;
}
else if (storageCapacity = 999)
{
costPerMonth = 25.00;
}
cout << 6.) How many years are you interest in hosting for?" << endl;
cin >> years;
这可能看起来有点混乱,但我正在绞尽脑汁试图解决它。你觉得怎么样?我走在正确的轨道上吗?我缺少哪些语句/运算符?我应该尝试合并开关语句吗?
switch 语句可能会使末尾具有存储容量的代码看起来更好,并且易于实现,但这只是偏好问题,对程序本身几乎没有好处。还要将 if 语句内容从赋值运算符 (=( 更改为比较 (==(,如注释所述。要清理您的 if else 混乱,您应该使用:
bool_name = answer == desired_input;
例如:
freeTheme = answer == 'y';
否则,您可以简单地询问他们想要的图片中的哪个选项(免费,博主..等(,并在 switch 语句中使用它。我会这样做,因为这意味着用户需要做更少的输入,可以在一行上看到所有选项,所以不需要考虑其他未来的选项,而且编码更容易。
相关文章:
- 为什么"do while"循环不断退出,即使条件计算结果为 false?
- valgrind-hellgrind与泄漏检查的结果不同
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 用C++20 fmt限制结果的总大小
- 如何返回一个类的两个对象相加的结果
- 在基于范围的for循环中使用结构化绑定声明
- 使用 LuaBridge 将 LuaJIT 绑定到C++会导致"PANIC: unprotected error"
- 使用QProcess执行命令,并将结果存储在QStringList中
- 如何让C++'tally up'结果并制定计划?
- 如何将 std::将结果绑定到 std::function
- 回复计划游戏结果不会显示
- 如何修改 std::generate 的绑定成员函数的结果
- C++ Poco SQL 查询不返回具有'between'和'and'日期时间绑定的结果
- 使用boost ::绑定结果作为参数
- (欧拉计划#3)试图将Python中的解决方案复制到C++,结果非常糟糕,不知道如何
- C++中的绑定函数结果
- 将带有占位符的绑定结果存储在 std::函数中
- 你能帮我解释一下C++计划的结果吗?
- 将lambda绑定到函数以获得返回结果
- 对象创建和绑定的奇怪结果