#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(){
int i;
int sales[30];
int arraySize = 0;
int temp[10] = { 0 };
for (i = 0; i < 30; i++)
{
sales[i] = (rand() % 15000) + 1; between 0 and 15000
}
printf("Gross Sales of all 30 Salespeople\n");
for (i = 0; i < 30; i++)
{
printf("%d\n", sales[i]); //Displays Orginal List and Lists all values that were randomly selected
}
printf("\nWage based on Gross Sales \n"); //Displays calculated wages with math equation
for (i = 0; i < 30; i++)
{
printf("%f\n", 100 + (float)sales[i] * 0.09); //Mathematical equation
}
for (i = 0; i < 30; i++)
while (arraySize >= 0)
{
{
if (sales[arraySize] >= 1000)
temp[9]++;
else if (sales[arraySize] >= 900)
temp[8]++;
else if (sales[arraySize] >= 800)
temp[7]++;
else if (sales[arraySize] >= 700)
temp[6]++;
else if (sales[arraySize] >= 600)
temp[5]++;
else if (sales[arraySize] >= 500)
temp[4]++;
else if (sales[arraySize] >= 400)
temp[3]++;
else if (sales[arraySize] >= 300)
temp[2]++;
else if (sales[arraySize] >= 200)
temp[1]++;
else
temp[0]++;
arraySize--;
printf("\n");
printf("$100-$199 : %d\n", temp[0]);
printf("$200-$299 : %d\n", temp[1]);
printf("$300-$399 : %d\n", temp[2]);
printf("$400-$499 : %d\n", temp[3]);
printf("$500-$599 : %d\n", temp[4]);
printf("$600-$699 : %d\n", temp[5]);
printf("$700-$799 : %d\n", temp[6]);
printf("$800-$899 : %d\n", temp[7]);
printf("$900-$999 : %d\n", temp[8]);
printf(">>>$1000 : %d\n", temp[9]);
break;
}
}
return 0;
我正在一個程序,在陣列中隨機地選擇30個號碼,然後使用對數的數學方程式,然後排序按照每個數組。除了將它們分類到每個選擇性組中時,我一直能夠使所有工作都能夠正常工作。我做錯了什麼,我該如何解決這個問題。 BTW即時消息程序,所以任何的幫助深表感謝
'arraySize'設置爲'0',然後不只是在最後'for'循環(它看起來像它預計將有非零值)又變了。 – kaylum
您將'0'分配給'arraySize',但在查看'sales [arraySize]'之前不要做任何其他操作,只需查看'sales [0]'。我認爲你的意思是遍歷「銷售」並根據內容進行排序?所以你只需要像計算時那樣使用for循環,並在比較中查看'sales [i]'。 – DigitalNinja
此外,您還打印出「數學公式」的值,但實際上並未將結果重新分配到「sales」數組中(看起來您要計算這些值的出現次數而非原始銷售值)。 – kaylum