函数为什么不接受数组输入?

时间:2019-07-13 01:37:20

标签: c++ arrays function

我尝试编译下面的代码,并且Xcode在第7行显示没有匹配的函数来调用'calcSubtotal'。

#include "header.h"
int itemCount[] = {0,0,0,0};
const double prices[] = {3.5,2.5,1.25,1.0};
int main() {
    getOrder();
    calcSubtotal(prices, itemCount);
    return 0;
}

void displayMenu()
{

    for(int i=1;i<5;i++){
        string item;
        switch (i) {
            case 1:
                item = "hotdog";
                break;
            case 2:
                item = "fries";
                break;
            case 3:
                item = "soda";
                break;
            case 4:
                item = "sauerkraut";
                break;
        }
        cout << i << " : " << item << endl;
    }
}

void getOrder()
{

    int flag;
    do{
        displayMenu();
        const string names[4] = {"hotdogs","fries","sodas","sauerkrauts"};
        int choice,count;
        cout << "Choose next item (input number corresponding to desired item): ";
        cin >> choice;
        int itemIndex = choice -1;
        cout << "How many orders of " << names[itemIndex] << " do you want ->";
        cin >> count;
        ::itemCount[itemIndex] += count;
        displayOrder(::itemCount);
        cout << "Are you done? (0 for no, any other number for yes):";
        cin >> flag;
    } while(flag==0);

}
void displayOrder(int itemCount[4])
{
    cout << "Your order -> " << endl;
    for(int i=1;i<5;i++){
        string item;
        switch (i) {
            case 1:
                item = "hotdog";
                break;
            case 2:
                item = "fries";
                break;
            case 3:
                item = "soda";
                break;
            case 4:
                item = "sauerkraut";
                break;
        }
        cout << i << "." << item << " : "<<itemCount[i-1] <<endl;
    }
}

double calcSubtotal(double prices[],double quantites[])
{
    double subtotal = 0.0;
    for(int i =0;i<4;i++)
        subtotal+=(prices[i]*quantites[i]);
    return subtotal;

}

0 个答案:

没有答案