【发布时间】:2017-09-22 22:19:34
【问题描述】:
该值从 0 开始,然后可以使用数学的任何操作数进行计算。代码编译成功,但不起作用。终端窗口显示“中止”、“重试”和“取消”。规则是您不能使用 2 个操作数,而只能将前一个数字添加到当前操作数。
#include <iostream>
#include <cmath>
using namespace std;
void Input(double input);
int main()
{
double sign, input;
cout << "This program calculates any given number upto 1 decimal place using the following operators:" << endl;
cout << " '+' - Addition." << endl;
cout << " '-' - Subtraction" << endl;
cout << " '*' - Multiplication." << endl;
cout << " '^' - Root." << endl;
cout << " '/' - Division." << endl;
Input(input);
return 0;
}
void Input(double IN)
{
char q;
char sign;
int Val = 0.0;
cin >> sign >> IN;
while (IN != q)
{
if (sign = '-')
Val -= IN;
if (sign = '+')
Val += IN;
if (sign = '*')
Val *= IN;
if (sign = '/')
Val /= IN;
cout << endl << "Result so far is " << IN;
IN++;
}
}
【问题讨论】:
-
强烈建议您明确指出给您带来麻烦的原因。我可以在代码中看到一个可能是问题的重复错误,但我宁愿有固定的球门柱。
-
程序不行,我想根据提供的操作符号来计算个数。
-
哪里不行?什么线条/表达?它做了什么而不是你想让它做什么?
-
它编译成功但不起作用。它说“运行时检查失败 #3-T”
-
您解决了所有编译器警告吗?编译器警告是来自编译器的重要消息,即使语法正确,您的逻辑也可能不正确。
标签: c++ visual-studio c++11 math visual-c++