制作一个纸牌是指操作员C
Make a charcter mean an operator c++
我正在尝试编写一个程序,该程序允许用户输入A,S,M或D。基本上,我要做的是使角色的含义增加,减法,乘法和划分。问题是我不确定如何做。这是我到目前为止的代码。
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
double num1;
double num2;
char operation;
cout<<"Enter the first number: ";
cin>>num1;
cout<<"Enter the second number: ";
cin>>num2;
cout<<"What would you like to do with the numbers? a-addition, s=subtraction, m=multiplacation, d=division";
cin>>operation;
检查开关语句:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
double num1;
double num2;
char operation;
cout<<"Enter the first number: ";
cin>>num1;
cout<<"Enter the second number: ";
cin>>num2;
cout<<"What would you like to do with the numbers? a-addition, s=subtraction, m=multiplacation, d=division";
cin>>operation;
switch(operation)
{
case 'a':
... // Addition code
break;
case 's':
... //Substraction code
break;
...
}
您也可以只使用每种类型的操作。
另外,作为提示,请考虑验证您的输入数据(尝试将更多字符键入程序或无效的选项键入)。
您使用开关:
switch (operation) {
case 'a': // addition
break;
case 's': // subtraction
break;
// ...
default: // none of these
break;
}
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 运行同一解决方案的另一个项目的项目
- 挂起和取消挂起一个文件DLL
- 我可以在C 中编程一个启动操作员吗?
- 使用超载操作员可以实现另一个操作员超载
- 模拟一个函数,该函数像操作员=和破坏者一样传播到每个字段
- 如何在C 中定义一个副操作员
- 为什么STD :: MAP需要操作员&lt;以及我如何写一个
- OpenCV:文件存储操作员">>"在一个项目中工作,但不在另一个项目中工作(在同一类上)
- 使用##预处理器操作员与另一个宏输出
- 写一个最小的自定义操作员:std :: Sort需要std :: __ lg为我的类型解释
- 为什么COUT在朋友函数中不起作用,该功能超载了操作员&lt;&lt;这是一个iStream运算符
- 为什么最后一个SR5对象不用重载的新操作员占据内存
- 制作一个纸牌是指操作员C
- 优先考虑一个操作员[]而不是另一个操作员
- 操作员 new 已经有一个主体
- 超载*操作员只能与一个施工人员一起工作
- 在unique_ptr上有一个铸造操作员有危险吗?