x2; cout>x3; cout>x4; cout>x5; 您是否忘记计算积分的总和值: cout << "Sum of integers: " << x1 + x2 + x3 + x4 + x5 << endl; cin >> SumOfIntegers; < >将它从 6代码>代码< 100代码> >中给出了一个不同的值—— 0.166667代码> VS 0.01 < /C> > < /P> < P>由于除法运算符如何在C++中工作(不要问为什么,它是哑的,但它是什么)当每个数字都是一个整数时,它会觉得很奇怪。如果在其中一个数字的末尾实现一个.0,它就会工作,floating-point,integer,Floating Point,Integer" /> x2; cout>x3; cout>x4; cout>x5; 您是否忘记计算积分的总和值: cout << "Sum of integers: " << x1 + x2 + x3 + x4 + x5 << endl; cin >> SumOfIntegers; < >将它从 6代码>代码< 100代码> >中给出了一个不同的值—— 0.166667代码> VS 0.01 < /C> > < /P> < P>由于除法运算符如何在C++中工作(不要问为什么,它是哑的,但它是什么)当每个数字都是一个整数时,它会觉得很奇怪。如果在其中一个数字的末尾实现一个.0,它就会工作,floating-point,integer,Floating Point,Integer" />

Floating point 如何从两个整数输入中产生十进制结果? 我在C++程序中编写了以下代码,但在结尾部分,我需要计算 x1/SUFFiTungs< /C>的值。我是一个完全的初学者,我非常感谢任何人能帮助我找出如何产生一个十进制结果作为答案。我一直使用2作为所有整数输入,因此x1=2和sumofingers=10。因此,x1/sumofinteger应该等于.2,但我一直得到1作为输出。有人能帮我吗 #include <iostream> #include "graphics.h" #define _USE_MATH_DEFINES #include "math.h" using namespace std; int main() { double x1; double x2; double x3; double x4; double x5; double SumOfIntegers; const double Radius = 250; double CircumferenceOfCircle; double x1PercentOfTotal; cout << "You will be prompted to enter five integers for a pie chart \n"; cout << "Enter integer 1: "; cin >> x1; cout << "Enter integer 2: "; cin >> x2; cout << "Enter integer 3: "; cin >> x3; cout << "Enter integer 4: "; cin >> x4; cout << "Enter integer 5: "; cin >> x5; cout << "Sum of integers: " << x1 + x2 + x3 + x4 + x5 << endl; cin >> SumOfIntegers; cout << "Circumference of Circle: " << 2 * (M_PI) * Radius << endl; cin >> CircumferenceOfCircle; cout << "x1 Percentage of Total " << (double)(x1) / (double)(SumOfIntegers) << endl; cin >> x1PercentOfTotal; return 0; } #包括 #包括“graphics.h” #定义使用数学定义 #包括“math.h” 使用名称空间std; int main() { 双x1; 双x2; 双x3; 双x4; 双x5; 双积分; 常数双半径=250; 双圆周; 占总数的两倍; cout-x1; cout>x2; cout>x3; cout>x4; cout>x5; 您是否忘记计算积分的总和值: cout << "Sum of integers: " << x1 + x2 + x3 + x4 + x5 << endl; cin >> SumOfIntegers; < >将它从 6代码>代码< 100代码> >中给出了一个不同的值—— 0.166667代码> VS 0.01 < /C> > < /P> < P>由于除法运算符如何在C++中工作(不要问为什么,它是哑的,但它是什么)当每个数字都是一个整数时,它会觉得很奇怪。如果在其中一个数字的末尾实现一个.0,它就会工作

Floating point 如何从两个整数输入中产生十进制结果? 我在C++程序中编写了以下代码,但在结尾部分,我需要计算 x1/SUFFiTungs< /C>的值。我是一个完全的初学者,我非常感谢任何人能帮助我找出如何产生一个十进制结果作为答案。我一直使用2作为所有整数输入,因此x1=2和sumofingers=10。因此,x1/sumofinteger应该等于.2,但我一直得到1作为输出。有人能帮我吗 #include <iostream> #include "graphics.h" #define _USE_MATH_DEFINES #include "math.h" using namespace std; int main() { double x1; double x2; double x3; double x4; double x5; double SumOfIntegers; const double Radius = 250; double CircumferenceOfCircle; double x1PercentOfTotal; cout << "You will be prompted to enter five integers for a pie chart \n"; cout << "Enter integer 1: "; cin >> x1; cout << "Enter integer 2: "; cin >> x2; cout << "Enter integer 3: "; cin >> x3; cout << "Enter integer 4: "; cin >> x4; cout << "Enter integer 5: "; cin >> x5; cout << "Sum of integers: " << x1 + x2 + x3 + x4 + x5 << endl; cin >> SumOfIntegers; cout << "Circumference of Circle: " << 2 * (M_PI) * Radius << endl; cin >> CircumferenceOfCircle; cout << "x1 Percentage of Total " << (double)(x1) / (double)(SumOfIntegers) << endl; cin >> x1PercentOfTotal; return 0; } #包括 #包括“graphics.h” #定义使用数学定义 #包括“math.h” 使用名称空间std; int main() { 双x1; 双x2; 双x3; 双x4; 双x5; 双积分; 常数双半径=250; 双圆周; 占总数的两倍; cout-x1; cout>x2; cout>x3; cout>x4; cout>x5; 您是否忘记计算积分的总和值: cout << "Sum of integers: " << x1 + x2 + x3 + x4 + x5 << endl; cin >> SumOfIntegers; < >将它从 6代码>代码< 100代码> >中给出了一个不同的值—— 0.166667代码> VS 0.01 < /C> > < /P> < P>由于除法运算符如何在C++中工作(不要问为什么,它是哑的,但它是什么)当每个数字都是一个整数时,它会觉得很奇怪。如果在其中一个数字的末尾实现一个.0,它就会工作,floating-point,integer,Floating Point,Integer,例: 2.0而不是2 此计算机上未安装visual studio,因此我无法验证x1+0.0是否正常工作,但需要尝试一些东西 此外,最好是计算总和,而不是输入 另外,你也不需要进行双精度运算。因为它们都已经是双精度运算了,你的双精度运算只能浪费时钟周期。只需x1/SumofInteger就可以了。谢谢!你能解释一下为什么删除cin>>SumofInteger就可以解决我的问题吗?我是一个完全的初学者,这是第一个专业选手gram我正在写。cin>>sumofingers用你在键盘上键入的任何数字覆

例:

2.0而不是2

此计算机上未安装visual studio,因此我无法验证x1+0.0是否正常工作,但需要尝试一些东西

此外,最好是计算总和,而不是输入


另外,你也不需要进行双精度运算。因为它们都已经是双精度运算了,你的双精度运算只能浪费时钟周期。只需x1/SumofInteger就可以了。

谢谢!你能解释一下为什么删除cin>>SumofInteger就可以解决我的问题吗?我是一个完全的初学者,这是第一个专业选手gram我正在写。
cin>>sumofingers
用你在键盘上键入的任何数字覆盖存储的值。:)通常是一个很好的捕捉,但是这些变量都声明为双精度的,尽管经常被称为整数。啊,是的,再次查看代码后,我发现它们都是双精度的,而不是整数/双精度组合。
SumOfIntegers = x1 + x2 + x3 + x4 + x5;
cout << "Sum of integers: " << SumOfIntegers << endl;
$ echo "1 2 3 4 5 6 8" | ./foo 
You will be prompted to enter five integers for a pie chart 
Enter integer 1: Enter integer 2: Enter integer 3: Enter integer 4: Enter integer 5: Sum of integers: 15
Circumference of Circle: 1570.8
x1 Percentage of Total 0.166667
$ echo "1 2 3 4 5 100 7" | ./foo 
You will be prompted to enter five integers for a pie chart 
Enter integer 1: Enter integer 2: Enter integer 3: Enter integer 4: Enter integer 5: Sum of integers: 15
Circumference of Circle: 1570.8
x1 Percentage of Total 0.01