Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/161.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将计算值分配到浮点数组-c++;_C++_Arrays - Fatal编程技术网

C++ 将计算值分配到浮点数组-c++;

C++ 将计算值分配到浮点数组-c++;,c++,arrays,C++,Arrays,我一直在尝试将那天计算的总收入放入一个数组中。最后,我可以对数组中的所有值求和,得到一个总数 到目前为止,我已经有了两个阵列,它们对馅饼的需求量和苹果的采摘量。为了计算馅饼、苹果托盘的收入和那天的总收入,我把它放进了一个for循环 到目前为止,我已经得到了:(这是用于在数组中输入计算值) float-total[30] int i, incmPie, numPie, rApples, applesLeft, FTray, incmFTray, PFTray; float totalincm, i

我一直在尝试将那天计算的总收入放入一个数组中。最后,我可以对数组中的所有值求和,得到一个总数

到目前为止,我已经有了两个阵列,它们对馅饼的需求量和苹果的采摘量。为了计算馅饼、苹果托盘的收入和那天的总收入,我把它放进了一个for循环

到目前为止,我已经得到了:(这是用于在数组中输入计算值)

float-total[30]

int i, incmPie, numPie, rApples, applesLeft, FTray, incmFTray, PFTray;
float totalincm, incmApples, incmRApples, incmPFTray, totalincome;
**float total[30];**
int pieDemand[30]={4, 4, 2, 7, 1, 6, 7, 8, 9, 12, 2,13,13, 5, 3, 9, 9, 9, 8, 7,
                   12, 1, 3, 3,10,12, 3, 6, 9, 3}; 
int applesPicked[30]={330,123,110,245,321,999,0,100,77,89,100,200,300,390,700,20,701,6,800,90,
                   600,45,690,700,719,790,800,1000,66,666};
int date[30] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30};
printf("\n==============================================================================");
printf("\n Date         Income from Pie         Income from Apples          Total income");
printf("\n==============================================================================");


for (i = 0 ; i <30; i++)
{
    if (applesPicked[i] == 0)
    {
        incmPie = 0;
        incmApples = 0;
        totalincm = 0;
        **total[i] = totalincm;**
    }

    else if (applesPicked[i] < (pieDemand[i]*8))
    {
        numPie = applesPicked[i]/8;
        incmPie = numPie * 14;
        rApples = applesPicked[i]%8;
        incmRApples = rApples * 0.5;
        incmApples = incmRApples;
        totalincm = incmPie + incmRApples;
        **total[i] = totalincm;**
    }

    else
    {
        incmPie = pieDemand[i] * 14;
        applesLeft = applesPicked[i] - (pieDemand[i]*8);
        FTray = applesLeft/20;
        incmFTray = FTray * 12;
        PFTray = applesLeft%20;
        incmPFTray = PFTray * 0.5;
        incmApples = incmFTray + incmPFTray;
        totalincm = incmApples + incmPie;
        **total[i] = totalincm;**
    }

    **totalincome** = total[1] + total[2] + total[3] + total[4] + total[5] + total[6] + total[7] + total[8] + total[9] + total[10] + total[11] + total[12] + total[13] + total[14] + total[15] + total[16] + total[17] + total[18] + total[19] + total[20] + total[21] + total[22] + total[23] + total[24] + total[25] + total[26] + total[27] + total[28] + total[29] + total[30];
    printf("\n"); //prints onto the next line.

    printf("%d/04/2013",date[i]); // prints the date.
    printf("%15d", incmPie); // prints the income from pies for each value in the arrays.
    printf("%20g", incmApples); // prints the income from apples from both full trays and remaining apples for each value in the arrays.
    printf("%28g", totalincm);
}
printf("\n==============================================================================");
**printf("\n Total income for the entire month: $%g", totalincome);**
printf("\n------------------------------------------------------------------------------");

_getch();
}
任何帮助都将不胜感激!:)

totalincome=0;
对于(int i=0;i
对于静态arrray,这将起作用。如果数组是作为指针动态分配或传递的,则必须跟踪元素的数量

totalincome = 0;
for (int i = 0; i < numelements; ++i)
     totalincome += total[i];
totalincome=0;
对于(int i=0;i
您需要将
totalincome
从循环中排除。

totalincome=0;
对于(int i=0;i
对于静态arrray,这将起作用。如果数组是作为指针动态分配或传递的,则必须跟踪元素的数量

totalincome = 0;
for (int i = 0; i < numelements; ++i)
     totalincome += total[i];
totalincome=0;
对于(int i=0;i
您需要将
totalincome
从循环中排除。

totalincome=0;
对于(int i=0;i
对于静态arrray,这将起作用。如果数组是作为指针动态分配或传递的,则必须跟踪元素的数量

totalincome = 0;
for (int i = 0; i < numelements; ++i)
     totalincome += total[i];
totalincome=0;
对于(int i=0;i
您需要将
totalincome
从循环中排除。

totalincome=0;
对于(int i=0;i
对于静态arrray,这将起作用。如果数组是作为指针动态分配或传递的,则必须跟踪元素的数量

totalincome = 0;
for (int i = 0; i < numelements; ++i)
     totalincome += total[i];
totalincome=0;
对于(int i=0;i

你需要把 ToalCuffy[/Cord] >循环。< /P> < P> <强> > C++(几乎所有的编程语言),数组索引从0开始,而不是1strong>查看更多信息

换成

totalincome = total[0] + total[1] + ... + total[29];
或者简单地说,为了让您的生活更轻松,请使用循环:

totalincome = 0;
for (int i = 0; i < sizeof(total)/sizeof(total[0]); ++i)
     totalincome += total[i];
totalincome=0;
对于(int i=0;i > P> <强> C++中(几乎所有的编程语言),数组索引从0开始,而不是1strong>查看更多信息

换成

totalincome = total[0] + total[1] + ... + total[29];
或者简单地说,为了让您的生活更轻松,请使用循环:

totalincome = 0;
for (int i = 0; i < sizeof(total)/sizeof(total[0]); ++i)
     totalincome += total[i];
totalincome=0;
对于(int i=0;i > P> <强> C++中(几乎所有的编程语言),数组索引从0开始,而不是1strong>查看更多信息

换成

totalincome = total[0] + total[1] + ... + total[29];
或者简单地说,为了让您的生活更轻松,请使用循环:

totalincome = 0;
for (int i = 0; i < sizeof(total)/sizeof(total[0]); ++i)
     totalincome += total[i];
totalincome=0;
对于(int i=0;i > P> <强> C++中(几乎所有的编程语言),数组索引从0开始,而不是1strong>查看更多信息

换成

totalincome = total[0] + total[1] + ... + total[29];
或者简单地说,为了让您的生活更轻松,请使用循环:

totalincome = 0;
for (int i = 0; i < sizeof(total)/sizeof(total[0]); ++i)
     totalincome += total[i];
totalincome=0;
对于(int i=0;i
问题是什么?此外,您还应该使用循环或库函数来处理total问题是什么?此外,您还应该使用循环或库函数来处理total问题是什么?此外,您还应该使用循环或库函数来处理total问题是什么?此外,您还应该使用循环或库函数来计算总数谢谢您的回答:)!谢谢你的回答:)!谢谢你的回答:)!谢谢你的回答:)!