标识符未定义和不兼容的声明

问题描述 投票:-2回答:1

我是c ++的新手,我的教科书也不是很有帮助。我的代码中有一些错误。我被告知customerAccount的标识符未定义,并且我在我的主要之前和之后与我的int搜索有一个不兼容的声明。我将在下面发布一些代码,因为我一直试图解决这个问题,我感到很茫然。

#include<iostream>
#include<string>
using namespace std;

struct {
    string Name;
    string Address;
    string City_State_Zip;
    double phoneNumber;
    double actBalance;
    string Payment;

};

//This is where the errors start, saying customer account is undefined
void Display(customerAccount ca);
//declaration is incompatible with int search
int Search(customerAccount, string);

int main() {

 customerAccount customers[10];
 string SName;

int choice, i = 0, size = 0;
do {
    cout << "****Menu****" << endl;
    cout << "1. Enter Customer Information" << endl;
    cout << "2. Change Customer Information" << endl;
    cout << "3. Search For Customer" << endl;
    cout << "4. Display Customer Data" << endl;
    cout << "5. Exit" << endl;
    cout << "Please enter a choice 1,2,3,4 or 5";
    cin >> choice;
    switch (choice) {
    case 1:
        cout << "Enter customer name: ";
        cin >> customers[i].Name;
        cout << "Enter customer address: ";
        cin >> customers[i].Address;
        cout << "Enter city state and zip: ";
        cin >> customers[i].City_State_Zip;
        cout << "Enter phone number: ";
        cin >> customers[i].phoneNumber;
        cout << "Enter account balance: ";
        cin >> customers[i].actBalance;
        if (customers[i].actBalance < 0) {
            cout << "Account balance cannot be negative. Please re-enter: " 
         << endl;
            cin >> customers[i].actBalance;
        }
        cout << "Enter last payment: ";
        cin >> customers[i].Payment;
        i++;
        break;

    case 2: int ele;
        cout << "Enter customer information to modify: " << endl;
        cout << "Enter customer name: ";
        cin >> customers[ele - 1].Name;
        cout << "Enter customer address: ";
        cin >> customers[ele - 1].Address;
        cout << "Enter city state and zip";
        cin >> customers[ele - 1].City_State_Zip;
        cout << "Enter phone number: ";
        cin >> customers[ele - 1].phoneNumber;
        cout << "Enter account balance: ";
        cin >> customers[ele - 1].actBalance;
        if (customers[ele - 1].actBalance < 0) {
            cout << "Account balance cannot be negative. Please re-enter: " 
        << endl;
            cin >> customers[i].actBalance;
        }
        cout << "Enter date of payment: ";
        cin >> customers[ele - 1].Payment;
        break;

    case 3: cout << "Enter customer name to search: ";
        cin >> SName;
        for (size = 0; size < i; size++) {
            int check;
            check = Search (customers[size], SName);
            if (check == 1)
                Display(customers[size]);
        }
        break;

    case 4:
        for (size = 0; size < i; size++)
            Display(customers[size]);

        break;
    case 5: exit(0);
        break;
    }
} while (choice != 5);
system("pause");
return 0;
}

void Display(customerAccount ca) {
    cout << " Customer name:";
    cout << ca.Name << endl;
    cout << " Address:";
    cout << ca.Address << endl;
    cout << " city state and zip:";
    cout << ca.City_State_Zip << endl;
    cout << " Phone number:";
    cout << ca.phoneNumber << endl;
    cout << " Account balance:";
    cout << ca.actBalance << endl;
    cout << " Date of payment:";
    cout << ca.Payment << endl;
}

//declaration is incompatible with int search
int Search(customerAccount ca, string str) {
if (str.compare(ca.Name) == 0)
    return 1;
else
    return 0;
}
c++ undefined
1个回答
0
投票
case 2: int ele;

在这一行,你有一个未初始化的变量,导致你的错误。

© www.soinside.com 2019 - 2024. All rights reserved.