{
// FIRST ARRAY
int NumberOfXValues;
double* FirstArray;
NumberOfXValues = 0;
FirstArray = new double[NumberOfXValues];
// END FIRST ARRAY
// SECOND ARRAY
int NumberOfProbabilities;
double* SecondArray;
NumberOfProbabilities = 0;
SecondArray = new double[NumberOfProbabilities];
// END SECOND ARRAY
// THIRD ARRAY
int Product;
double* ThirdArray;
Product = 0;
ThirdArray = new double[Product];
// END THIRD ARRAY
// OBTAINING THE NUMBER OF X VALUES
cout << "Please input the number of \"x\" values we will be using: ";
cin >> NumberOfXValues;
// END OF OBTAINING THE NUMBER OF X VALUES
// OBTAINING THE VALUES IN THE FIRST ARRAY
int x;
cout << "Please input the \"x\" values in order from least to greatest: " << endl;
cout << endl;
for (int x = 0; x < NumberOfXValues; x++)
{
cout << "Enter number: ";
cin >> FirstArray[x];
}
cout << endl;
// END OF OBTAINING THE VALUES IN THE FIRST ARRAY
// OBTAINING THE VALUES IN THE SECOND ARRAY
cout << "Please input the probabilities corresponding to their \"x\" values: " << endl;
cout << endl;
for (int x = 0; x < NumberOfXValues; x++)
{
cout << "Enter probability in decimal form: ";
cin >> SecondArray[x];
}
cout << endl;
// END OF OBTAINING THE VALUES IN THE SECOND ARRAY
// MULTIPLYING THE FIRST TWO ARRAYS TO OBTAIN THE THIRD
for (int x = 0; x < NumberOfXValues; x++)
{
ThirdArray[x] = FirstArray[x] * SecondArray[x];
}
// END OF MULTIPLYING THE FIRST TWO ARRAYS TO OBTAIN THE THIRD
//TEST
for (int x = 0; x < NumberOfXValues; x++)
{
cout << ThirdArray[x];
cout << endl;
}
//TEST
}
這是我第一次使用這些網站之一,但我已經工作了近一個小時來解決這個問題。它運行完全平滑,直到它顯示第三個數組中的第三個值。它總是給我一個奇怪的數字。我的動態陣列發生故障
您正在爲數組分配空間爲0的項目。等到你得到尺寸來分配它們。 –