Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is my program, it dosen't seem to be properly filling the array when I call updateClnt function. Any ideas? I also get an identifier

Here is my program, it dosen't seem to be properly filling the array when I call updateClnt function. Any ideas?

I also get an identifier bAccounts is undefined, but only sometimes.

#include "pch.h" #include #include #include

using namespace std;

struct Client { int id; string name; string zip; double balance; string lastTrans;

};

int menu(); int addClnt(Client(&bAccounts)[30], int); void updateClnt(Client(&bAccounts)[30], int); void displayClnt(Client(&bAccounts)[30], int); int findClnt(Client(&bAccounts)[30], int, int);

int menu() {

cout << " Menu of choices "; cout << "++++++++++++++++++++++++++++++++++++++ "; cout << "1. Enter new account information "; cout << "2. Change account information "; cout << "3. Display all account information "; cout << "4. Find a client "; cout << "5. Exit the program ";

int choice; cin >> choice;

while ((!cin >> choice) || (choice < 1 || choice > 5)) { cout << " Please enter a correct option " << endl; cin.clear(); cin.ignore(numeric_limits::max(), ' '); cin >> choice; }

return choice; }

int addClnt(Client(&bAccounts)[30], int clientCount) { int i = 0; int tempID = 0;

cout << "Enter Account Number:" << endl; cin >> tempID;

while ((!cin >> tempID)) { cout << " Please enter a correct option " << endl; cin.clear(); cin.ignore(numeric_limits::max(), ' '); cin >> tempID; }

for (int j = 0; j < 30; j++) { if (bAccounts[j].id == tempID) { cout << "Customer ID already used "; } while (bAccounts[j].id == tempID) { cout << "Retry Customer ID "; cin.clear(); cin.ignore(); cin >> tempID; } }

bAccounts[i].id = tempID;

cout << "Enter Account Name:" << endl; cin >> bAccounts[i].name;

cout << "Enter Account Zip:" << endl; cin >> bAccounts[i].zip;

cout << "Enter Account Balance:" << endl; cin >> bAccounts[i].balance;

if (bAccounts[i].balance < 0) { cout << "Invalid. Negative balances aren't allowed "; cout << "Enter Account Balance "; } while (bAccounts[i].balance < 0) { cin.clear(); cin.ignore(); cin >> bAccounts[i].balance; }

cout << "Enter Last Transaction" << endl; cin >> bAccounts[i].lastTrans;

clientCount++; i++;

return clientCount, i;

} void updateClnt(Client(&bAccounts)[30], int clientCount) { int clientLookup; int position;

cout << "Enter User's ID "; cin >> clientLookup;

position = findClnt(bAccounts, clientCount, clientLookup);

if (position == -1) { cout << "Client not found"; }

else { int found = false; int i = 0; int tempID = 0;

cout << "Enter Account Number:" << endl; cin >> tempID;

while ((!cin >> tempID)) { cout << " Please enter a correct option " << endl; cin.clear(); cin.ignore(numeric_limits::max(), ' '); cin >> tempID; }

for (int j = 0; j < clientCount; j++) { if (bAccounts[j].id == tempID) { cout << "Customer ID already used "; } while (bAccounts[j].id == tempID) { cout << "Retry Customer ID "; cin.clear(); cin.ignore(); cin >> tempID; } }

bAccounts[i].id = tempID;

cout << "Enter Account Name:" << endl; cin >> bAccounts[i].name;

cout << "Enter Account Zip:" << endl; cin >> bAccounts[i].zip;

cout << "Enter Account Balance:" << endl; cin >> bAccounts[i].balance;

if (bAccounts[i].balance < 0) { cout << "Invalid. Negative balances aren't allowed "; cout << "Enter Account Balance "; } while (bAccounts[i].balance < 0) { cin.clear(); cin.ignore(); cin >> bAccounts[i].balance; }

cout << "Enter Last Transaction" << endl; cin >> bAccounts[i].lastTrans;

clientCount++; } } void displayClnt(Client(&bAccounts)[30], int clientLookup) { cout << "Enter Client ID "; cin >> clientLookup;

int position = -1; bool found = false; int i = 0;

while (!found) { for (int i = 0; i < 30; i++) if (clientLookup == bAccounts[i].id) { found = true; position = i; break; }

}

cout << "Account ID: " << bAccounts[i].id << endl << "-------------------------" << endl; cout << "Account Name: " << bAccounts[i].name << endl << "-------------------------" << endl; cout << "Account Zip: " << bAccounts[i].zip << endl << "-------------------------" << endl; cout << "Account Balance: " << bAccounts[i].balance << endl << "-------------------------" << endl; cout << "Account Last Transaction: " << bAccounts[i].lastTrans << endl << "-------------------------" << endl;

} int findClnt(Client(&bAccounts)[30], int clientCount, int clientLookup) { int position = -1; bool found = false;

while (!found) { for (int j = 0; j < 30; j++) if (clientLookup == bAccounts[j].id) { found = true; position = j; } }

return position; }

int main() { const int MAXCLNT = 30; Client bAccounts[MAXCLNT];

int clientCount = NULL; int clientLookup = NULL; int position; int choice;

choice = menu();

do { if (choice == 1) { addClnt(bAccounts, clientCount); } if (choice == 2) { updateClnt(bAccounts, clientCount); } if (choice == 3) { displayClnt(bAccounts, clientLookup); } if (choice == 4) { findClnt(bAccounts, clientCount, clientLookup); position = findClnt(bAccounts, clientCount, clientLookup);

if (position = -1) { cout << "Client not found"; }

else { displayClnt(bAccounts, clientLookup); }

}

choice = menu();

} while (choice != 5);

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions