Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.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++ - Fatal编程技术网

C++ 显示最高销售额和平均销售额

C++ 显示最高销售额和平均销售额,c++,C++,L在C++中有这个程序可以找到最高的销售数字和平均值,但是下面给出的错误请帮助< /P> #include <iostream> using namespace std; // You must add the three functions here void getSales(float & sales1P, float & sales2P, float & sales3P, float & sales4P) { c

L在C++中有这个程序可以找到最高的销售数字和平均值,但是下面给出的错误请帮助< /P>
#include <iostream>

using namespace std;

// You must add the three functions here

void getSales(float & sales1P, float & sales2P, float & sales3P,
        float & sales4P) {

    cout << "Enter four sales values: " << endl;

    cin >> sales1P >> sales2P >> sales3P >> sales4P;
}

float calcAverage(float sales1P, float sales2P, float sales3P, float sales4P) {

    return (sales1P + sales2P + sales3P + sales4P) / 4;
}

float findHighest(float sales1P, float sales2P, float sales3P, float sales4P)

{

    float highest = sales1P;
    if (sales2P > highest)
        highest = sales2P;
    if (sales3P > highest)
        highest = sales3P;
    if (sales4P > highest)
        highest = sales4P;
}

void displayOutput(float highestSales, float averageSales) {
    cout << "The highest sales figure is " << highestSales

    << " with an average of " << averageSales << endl;
}

int main()

{
    float sales1,
    sales2,
    sales3,
    sales4;
    float averageSales;
    float highestSales;
    for (int i = 0; i < 4; i++)
    // Get the sales for each division.
    sales1 = getSales();
    sales2 = getSales();
    sales3 = getSales();
    sales4 = getSales();
    //
    //getSales(sales1, sales2, sales3, sales4);
    averageSales = calcAverage(sales1, sales2, sales3, sales4);
    //getSales(sales1, sales2, sales3, sales4);
    highestSales = findHighest(sales1, sales2, sales3, sales4);
    displayOutput(highestSales, averageSales);
    system("PAUSE");
    return 0;
}
在本节:

sales1 = getSales();

sales2 = getSales();

sales3 = getSales();

sales4 = getSales();
您正在使用一个名为(getSales)的函数,该函数应该具有以下签名:getSales(float&,float&,float&,float&)。这意味着该函数接受4个参数,您给它0

// getSales(sales1, sales2, sales3, sales4);
没错。为什么要注释掉它并直接针对您定义的函数的参数计数


另外,您的
for
循环可能没有执行您认为它正在执行的操作。您忘记了
{}
。您现在拥有的将只执行第一行4次。

这是您的函数定义:

void getSales(float & sales1P, float & sales2P, float & sales3P, float & sales4P)
你是这样称呼它的:

sales1 = getSales();

sales2 = getSales();

sales3 = getSales();

sales4 = getSales();
你看到定义和如何调用之间的脱节了吗

您需要使用4个浮点地址调用getSales()

编辑:由于OP似乎在压缩它时遇到了问题

#include<iostream>
using namespace std;

// You must add the three functions here
//changed these to take pointers to floats
void getSales(float *sales1P, float *sales2P, float *sales3P, float *sales4P) {

cout << "Enter four sales values: " <
//Changed the cin to store in the content of pointers
cin >> *sales1P >> *sales2P >> *sales3P >> *sales4P; }

float calcAverage(float sales1P, float sales2P, float sales3P, float sales4P) {

return (sales1P + sales2P + sales3P + sales4P) / 4; }

float findHighest( float sales1P, float sales2P, float sales3P, float sales4P)

{

float highest = sales1P;
if (sales2P > highest)
    highest = sales2P;
if (sales3P > highest)
    highest = sales3P;
if (sales4P > highest)
    highest = sales4P;
//You were for some reason missing the return statement on highest here. 
return highest;
}

void displayOutput(float highestSales, float averageSales) { cout << "The highest sales         figure is " << highestSales  << " with an average of " << averageSales <<endl;
}

int main()

{

float sales1,sales2,sales3,sales4;

float averageSales;

float highestSales;

//for (int i = 0; i < 4; i++)

// Get the sales for each division.
//The For loop here is useless. Call the function with the addresses of the float values. 
getSales(&sales1, &sales2, &sales3, &sales4);


averageSales = calcAverage(sales1, sales2, sales3, sales4);



highestSales = findHighest(sales1, sales2, sales3, sales4);

displayOutput(highestSales, averageSales);

system("PAUSE");

return 0;

}
#包括
使用名称空间std;
//您必须在此处添加这三个函数
//更改这些以获取指向浮动的指针
作废getSales(浮动*sales1P,浮动*sales2P,浮动*sales3P,浮动*sales4P){
cout>*sales1P>>*sales2P>>*sales3P>>*sales4P;}
浮动平均值(浮动销售1P、浮动销售2P、浮动销售3P、浮动销售4P){
返回(sales1P+sales2P+sales3P+sales4P)/4;}
浮动findHighest(浮动销售1P、浮动销售2P、浮动销售3P、浮动销售4P)
{
浮动最高=销售1便士;
如果(销售2P>最高)
最高=销售2p;
如果(销售3P>最高)
最高=销售3P;
如果(销售4P>最高)
最高=销售4P;
//出于某种原因,你错过了这里最上面的返回语句。
回报最高;
}

void display output(float highestSales,float average sales){难道这不应该被标记为任何其他语言吗这些错误都是不言自明的。你对它们有什么不理解吗?谢谢…我如何克服错误谢谢…问题是我如何调用这些函数任何示例都会有所帮助
#include<iostream>
using namespace std;

// You must add the three functions here
//changed these to take pointers to floats
void getSales(float *sales1P, float *sales2P, float *sales3P, float *sales4P) {

cout << "Enter four sales values: " <
//Changed the cin to store in the content of pointers
cin >> *sales1P >> *sales2P >> *sales3P >> *sales4P; }

float calcAverage(float sales1P, float sales2P, float sales3P, float sales4P) {

return (sales1P + sales2P + sales3P + sales4P) / 4; }

float findHighest( float sales1P, float sales2P, float sales3P, float sales4P)

{

float highest = sales1P;
if (sales2P > highest)
    highest = sales2P;
if (sales3P > highest)
    highest = sales3P;
if (sales4P > highest)
    highest = sales4P;
//You were for some reason missing the return statement on highest here. 
return highest;
}

void displayOutput(float highestSales, float averageSales) { cout << "The highest sales         figure is " << highestSales  << " with an average of " << averageSales <<endl;
}

int main()

{

float sales1,sales2,sales3,sales4;

float averageSales;

float highestSales;

//for (int i = 0; i < 4; i++)

// Get the sales for each division.
//The For loop here is useless. Call the function with the addresses of the float values. 
getSales(&sales1, &sales2, &sales3, &sales4);


averageSales = calcAverage(sales1, sales2, sales3, sales4);



highestSales = findHighest(sales1, sales2, sales3, sales4);

displayOutput(highestSales, averageSales);

system("PAUSE");

return 0;

}