C 给我2个基本计算的不同答案
C++ giving me 2 different answers to basic calculation
当我运行此操作时,我在if语句之外得到正确的答案,而在if语句中的错误答案。前3和3的长度和宽度给了我9,但在内部条件下它给了我92。我尝试了Double Float int ...任何帮助都很棒...
cout << "you entered 2 for Rectanglen";
cout << "Enter the length of the Rectangle.n";
cin >> lengthRec;
cout << "Enter the width of the Rectangle.n";
cin >> widthRec;
areaRec = lengthRec * widthRec;
cout << areaRec;
if ((lengthRec > 0) && (widthRec > 0)) {
areaRec = lengthRec * widthRec;
cout << "nlength is " << lengthRec << "n"<< "width is " <<
widthRec << "n";
cout << "The area is ";
cout << areaRec;
}
else {
cout << "Invalid entry, Please re run with a positive numbern";
}
效果很好,没有问题 - 以后再设计,因为您没有' n'
#include <iostream>
#include <stdio.h>
#include <iostream>
using namespace std;
int main(){
int lengthRec, widthRec, areaRec;
cout << "you entered 2 for Rectanglen";
cout << "Enter the length of the Rectangle.n";
cin >> lengthRec;
cout << "Enter the width of the Rectangle.n";
cin >> widthRec; //CHECK HERE
areaRec = lengthRec * widthRec;
cout << areaRec<<"n";
if ((lengthRec > 0) && (widthRec > 0)) {
areaRec = lengthRec * widthRec;
cout << "nlength is " << lengthRec << "n"<< "width is " <<
widthRec << "n";
cout << "The area is ";
cout << areaRec<<"n"; //CHECK HERE
}
else {
cout << "Invalid entry, Please re run with a positive numbern";
}
return 0;
}
输出: -
you entered 2 for Rectangle
Enter the length of the Rectangle.
Enter the width of the Rectangle.
9
length is 3
width is 3
The area is 9
相关文章:
- 为什么"do while"循环不断退出,即使条件计算结果为 false?
- 递归函数计算序列中的平方和(并输出过程)
- 欧拉项目#8答案是大以获得有效答案
- (C++)分析树以计算返回错误值的简单算术表达式
- 我的字符计数代码计算错误.为什么
- C 给我2个基本计算的不同答案
- 使用幂函数的计算给出了大数字的错误答案
- 我正在尝试编写一个简单的计算程序,但答案一直返回为 0
- 如果遵循IEEE 754的两种语言,则两种语言的计算都会产生相同的答案
- 一个简单的C 功能,在不同的计算机上具有不同的答案
- 如何计算循环中正确答案的数量
- 无法计算如何从联机答案中返回c++函数的多个值
- 为什么此代码不显示计算的正确答案,为什么它会无限循环?
- 如何计算对该函数的递归调用,以及正确答案是什么
- 计算函数中的模给出了与直接使用%运算符不同的答案
- 计算未输出预期答案
- 使用迭代和递归计算阶乘时的不同答案
- 在计算cpp中数字的n次方根时,答案错误
- 阶乘在main中显示错误的答案.在函数中正确计算
- 浮点数——为什么c++对看似相同的计算给出了不同的答案?