C++简单的计算器
Simple calculator in C++
我正在构建一个简单的计算器作为学习练习,但我磕磕绊绊 - 我得到了第一个数字的用户输入,但它无法存储第二个输入的 int - 我需要创建对象吗?我认为这是一个明显的问题...
//Simple calculator to work out the sum of two numbers (using addition)
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
cout << "Enter the first int: n";
int input1 = std::cin.get();
cout << "Enter the second int: n";
int input2 = std::cin.get();
cout << "The sum of these numbers is: " << input1 + input2;
cout << "n";
system("PAUSE");
return EXIT_SUCCESS;
}
cin.get()
只检索输入的一个字符。为什么不使用
int input1, input2;
cout << "Enter the first int: n";
cin >> input1;
cout << "Enter the second int: n";
cin >> input2;
以这种方式使用std::cin
(使用 operator>>
)还可以处理用户输入的任何多余的换行符或空格字符。
相关文章:
- C++ - 在我尝试制作一个简单的计算器时有一个"uninitialized local variable y used"警告
- 创建一个简单的计算器,添加时遇到问题
- 简单计算器的难以理解功能(Stroustrop 编程原理书)
- C++:我的简单计算器程序无法打印出来。我也认为我的变量命名不正确
- DEV简单的C GPA计算器问题
- 在特定条件下的循环和简单计算器的结尾
- C++简单的计算器(没有如果,开关,案例及其种类)
- 简单平均计算器的问题
- 使用命令行和C++的简单计算器
- C++简单的计算器
- 简单的计算器程序出了什么问题
- 简单计算器C++
- 简单的计算器
- C++ - 简单的形状面积计算器返回错误的计算
- 简单计算器尝试重新学习C++.左值错误
- 简单的计算器应该需要2秒钟来修复它的10行
- 简单的计算器问题(不输出答案)
- 模板化一个简单的Boost Proto C++表达式计算器
- 简单平均计算器c++不能正常工作
- 简单的c++计算器代码审查