- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想用 c 编写基本计算器:我有累加器的问题(带有“+”和“-”运算符)
int main(void)
{
float num1,num2,res;
char operator;
printf ("Type in your expression.\n");
scanf ("%f %c %f", &num1, &operator, &num2);
if(operator == 'S'){
printf(" = %.2f\n",num1);
res = num1;
while(1){
printf ("Type in your expression.\n");
scanf ("%c %f", &operator, &num2);
if(operator == '+'){
res += num2;
printf("%.2f\n", res);
}
else if(operator == '-'){
res -=num2;
printf("%.2f\n",res);
}
else if(operator == '*'){
res *=num2;
printf("%.2f\n",res);
}
else if(operator == '/'){
if(num2 == 0)
printf("Division by zero\n");
else
res /=num2;
printf("%.2f\n",res);
}
else if(operator == 'E'){
printf("End of the calculation:");
printf("%.2f",res);
break;
}
}
}
在这部分代码中,除法和乘法工作正常:但是当我在累加器中输入类似“+3”或“-2”的东西时,什么也没有发生。我不知道问题出在哪里。
最佳答案
我认为这是因为在下面的命令中:
scanf ("%c %f", &operator, &num2);
当您在程序等待读取运算符和数字时键入 +3 时,它会将 +3 作为数字而不是 + 作为运算符和 3 作为数字。因此您必须给出 + 3(尽快分离)。我试过了,我认为它有效!!
关于c语言的计算器(累加器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39332231/
我想用 c 编写基本计算器:我有累加器的问题(带有“+”和“-”运算符) int main(void) { float num1,num2,res; char operator;
我已经解决了 4clojure.com 上的 45 个问题,并且在尝试使用递归和累加器解决一些问题的方式中,我注意到一个反复出现的问题。 我会尽我所能解释我正在做的事情,以最终得到模糊的解决方案,希望
my_Stream 是我想要累积并分配给变量以供进一步处理的数据。我的问题:一旦流完成,如何将变量 the_string 的内容获取到 console.log? my_Stream.onValue(f
我很好奇,从这个代码片段中得到的平均值是多少?累加器旨在为空。 boost::accumulators::accumulator_set > Accumulator; int Mean = boost
在累积 struct timespec 增量的程序中,我正在执行以下逻辑: struct timespec accu, start, stop; for (...) { // record s
我正在尝试在数组上使用 foldLeft。例如: var x = some array x.foldLeft(new Array[Int](10))((a, c) => a(c) = a(c)+1)
由于没有找到在 C++ 中重置累加器的“boost ”方法,我遇到了一段似乎可以重置 boost 累加器的代码。但是不明白它是如何实现的。代码如下- #include #include #incl
这个问题在这里已经有了答案: Does a sequential stream in Java 8 use the combiner parameter on calling collect? (1
我正在实现一个需要递归调用才能获取所有数据的 API。我已经实现了一个具有 recursive transformer 的 Bloc 组件。但是,转换器似乎一直在递归调用中返回空累加器。 commen
我永远找不到 F# 核心库的源代码。我知道它应该是开放的,但谷歌在帮助我找到它时对我并不友好,如果是这样,我会查找 Seq.fold 的实现 - 但问题就在这里。 有没有人看到以下代码段有任何问题:
最近我学习了很多 Haskell,并想尝试一些它在 Python 中的巧妙技巧。据我了解,Python的reduce会自动将函数中的迭代变量和累加器设置为reduce中给出的列表的前两个值。在 Has
documentation boost 累加器的 error_of 特性说明它通过以下公式计算平均值的误差: 平方(方差/(计数 - 1)), 其中方差的计算方式是: variance = 1/cou
我正在使用 LongAccumulator 来计算我在 Cassandra 中保存的记录数。 object Main extends App { val conf = args(0) val
Spark 有一个有用的 API,用于以线程安全的方式积累数据 https://spark.apache.org/docs/2.3.0/api/scala/index.html#org.apache.
我想从任意长度的列表中选择任意数量的项目。下拉列表 (QComboBox) 不允许选中项目。如果有很多项目,可检查项目的列表会变得笨拙。 我找到了 this question在用户体验 SE 子站点和
是否可以在分组时通过集合收集字符串?这就是它在 Java 8 中的工作方式: Map discountOptions = p.getDiscountOptions().Stream() .
我是一名优秀的程序员,十分优秀!