我在我的 C++ 程序中编写了以下代码,但在接近尾声时,我需要计算x1 / SumOfIntegers
. 我是一个完全的初学者,我非常感谢任何可以帮助我弄清楚如何产生小数结果作为答案的人。我一直使用 2 作为我所有的整数输入,所以x1 = 2
和SumOfIntegers = 10
. 因此x1 / SumOfIntegers
应该相等.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;
}