【发布时间】:2017-08-12 15:01:51
【问题描述】:
我的程序是一个计算器,目前只做加法和减法,但是当我输入一个大数字时它开始闪烁和滚动。它适用于小数字。该程序不长,所以就在这里。该问题的 youtube 视频https://youtu.be/Fa03WtgXoek
#include <iostream>
int GVFU()
{
std::cout <<"enter number";
int a;
std::cin >> a;
return a;
}
int add()
{
int x = GVFU();
int y = GVFU();
int z = x + y;
std::cout <<z <<std::endl;
return 0;
}
int subtract()
{
int x = GVFU();
int y = GVFU();
int z = x - y;
std::cout <<z << std::endl;
return 0;
}
int main()
{
for ( ; ; )
{
std::cout << "enter 1 for addition and 2 for subtraction";
int c;
std::cin >> c;
if (c==1)
{
add();
}
if (c==2)
{
subtract();
}
std::cout << "press 1 to end";
int e;
std::cin >>e;
if (e==1)
{
return 0;
}
}
}
【问题讨论】:
-
您的输入读取功能失败,您没有在任何地方检查错误。
-
您可能正在接受一个字符来代替整数,从而进入一个无限循环。有关该主题的更多信息in this question。
标签: c++