-2

I am new to c++ and my textbook is not very helpful. I have a few errors in my code. Where I am being told the identifier for customerAccount is undefined, and I have an incompatible declaration with my int search before and after my main. I will post some code below as I have been trying to figure this out for a while and I am at a loss.

#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;
}
B.Moe09
  • 51
  • 2
  • 10
  • 1
    You never gave your struct a name, the compiler doesn't know what on Earth `customerAccount` is. – eesiraed Apr 02 '19 at 04:32
  • I have fixed that part of my code. Now when I run the program it breaks after I enter an address. I'm not sure whats going on, visual studio is not showing me any errors – B.Moe09 Apr 02 '19 at 04:37
  • 1
    You forgot to read `ele` from the user. So you have an uninitialized variable, and start doing pointer math with it. – Ben Voigt Apr 02 '19 at 05:03
  • Please do not change your question by fixing with comments/answers. That changes the question. If after getting one question answered you have another different problem, then make a new question of it. However, if the comments on the deleted answers are correct (that the problem is with tydefs/structs) and the actual solution is different and the changed question better explains that - then ignore this comment. (And let me know if you like.) – Yunnosch Apr 02 '19 at 06:08

1 Answers1

0
case 2: int ele;

On this line you have an uninitialized variable which is causing your bug.

darune
  • 10,480
  • 2
  • 24
  • 62