Question

I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7:...

I need help with this code. I'm using C++ and Myprogramming lab to execute it.

11.7: Customer Accounts
Write a program that uses a structure to store the following data about a customer account:

     Customer name
     Customer address
     City
     State
     ZIP code
     Telephone
     Account balance
     Date of last payment

The program should use an array of at least 20 structures. It should let the user enter data into the array, change the contents of any element, and display all the data stored in the array. The program should have a menu-driven user interface.

Prompts And Output Labels. Your main menu should be the following:
     1. Enter new account information
     2. Change account information
     3. Display all account information
     4. Exit the program
The user is expected to enter 1 or 2 or 3 or 4.
The main menu is displayed at the start of the program and after the handling of choices 1, 2 and 3.

If 1 is entered for the main menu, the program prompts for each of the data listed above, in the order listed above, using the above data descriptions (e.g. "ZIP code") as prompts (followed in each case by a colon). After reading in and processing the data, the program prints
     You have entered information for customer number X
where X is the customer number: 0 for the first customer and increasing by 1 for each subsequent customer that is entered.

If 2 is entered for the main menu, the program prompts for the customer number:
     Customer number:
Upon entering a valid customer number the program displays all the data for the particular customer that has been saved:
     Customer name: ...
     Customer address: ...
     City: ...
     State: ...
     ZIP code: ...
     Telephone: ...
     Account balance: ...
     Date of last payment: ...

The program then skips one or two lines and prompts for a change, using the same prompts as in choice 1 above for all the data items associated with a customer.

If 3 is entered for the main menu, the program displays all the data for each customer that has been saved, using the display format in choice 2 above. After the display of each customer the program prompts "Press enter to continue..." and waits for the user to hit return.

If 4 is entered for the main menu, the program terminates.

Input Validation (OPTIONAL).When the data for a new account is entered, be sure the user enters data for all the fields. No negative account balances should be entered.

Here is my code:

#include<iostream>

using namespace std;

#include<string>

struct CustomerAccount

{

string customerName;

string customerAddress;

string city;

string state;

int zip_code;

long long telephone;

double accountBalance;

string last_payment_date;

};

int main()

{

int choice, index = 0;

int customerNumber;

struct CustomerAccount accountObject[20];

while (1)

{

cout << endl;

cout << "\n1. Enter new account information" << endl;

cout << "2. Change account information" << endl;

cout << "3. Display all account information" << endl;

cout << "4. Exit the program " << endl;

cout << endl;

cout << "Enter choice :";

cin >> choice;

switch (choice)

{

case 1:

{

cout << "Enter Customer customerName :";

cin >> accountObject[index].customerName;

cin.ignore();

cout << "Enter customerAddress :";

std::getline(std::cin, accountObject[index].customerAddress);

cout << "Enter city :";

cin >> accountObject[index].city;

cout << "Enter state :";

cin >> accountObject[index].state;

cout << "Enter Zip code :";

cin >> accountObject[index].zip_code;

cout << "Enter mobile number :";

cin >> accountObject[index].telephone;

cout << "Enter account Balance :";

cin >> accountObject[index].accountBalance;

cout << "Enter last payment date :";

cin >> accountObject[index].last_payment_date;

index++;

continue;

}

case 2:

{


while (1)

{

cout << "Enter customer number :";

cin >> customerNumber;

if (customerNumber < 0 || customerNumber >= index)

{

cout << "Invalid.Must be greater than 0 and less than " << index << endl;

continue;

}

else

break;

}

cout << endl << endl;

cout << "Customer customerName :" << accountObject[customerNumber].customerName << endl;

cout << "Customer customerAddress:" << accountObject[customerNumber].customerAddress << endl;

cout << "City:" << accountObject[customerNumber].city << endl;

cout << "State:" << accountObject[customerNumber].state << endl;

cout << "Zip code :" << accountObject[customerNumber].zip_code << endl;

cout << "Telephone :" << accountObject[customerNumber].telephone << endl;

cout << "Account accountBalance:" << accountObject[customerNumber].accountBalance << endl;

cout << "Date of last payment:" << accountObject[customerNumber].last_payment_date << endl;

cout << endl << endl;

cout << "Enter customerName :";

cin >> accountObject[customerNumber].customerName;

cin.ignore();

cout << "Enter customer Address :";

std::getline(std::cin, accountObject[customerNumber].customerAddress);

cout << "Enter city :";

cin >> accountObject[customerNumber].city;

cout << "Enter state :";

cin >> accountObject[customerNumber].state;

cout << "Enter Zip code :";

cin >> accountObject[customerNumber].zip_code;

cout << "Enter mobile number :";

cin >> accountObject[customerNumber].telephone;

cout << "Enter accountBalance :";

cin >> accountObject[customerNumber].accountBalance;

cout << "Enter last payment date :";

cin >> accountObject[customerNumber].last_payment_date;

continue;

}

case 3:

{


for (int i = 0; i < index; i++)

{

cout << "Customer Name :" << accountObject[i].customerName << endl;

cout << "Customer Address:" << accountObject[i].customerAddress << endl;

cout << "City:" << accountObject[i].city << endl;

cout << "State:" << accountObject[i].state << endl;

cout << "Zip code :" << accountObject[i].zip_code << endl;

cout << "Telephone :" << accountObject[i].telephone << endl;

cout << "Account accountBalance:" << accountObject[i].accountBalance << endl;

cout << "Date of last payment:" << accountObject[i].last_payment_date << endl;

cout << "Press enter to continue..." << endl;

system("PAUSE");

}

continue;

}

case 4:

{

cout << "Program Exit" << endl;

break;

}

default:

{

cout << "Invalid input.Must be 1 or 2 or 3" << endl;

continue;

}

}

break;

}

return 0;

}

Here is the error code I keep getting:

CODELAB ANALYSIS: LOGICAL ERROR(S)


Remarks:
          When executed, your code tried to create an excessively large file. A common cause for this is an infinite loop. Carefully check the condition and the loop body of any loop that does output.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please let me know if anything is required. The code I have changed is in bold.

Copyable code:

#include<iostream>
#include<stdlib.h>

using namespace std;

#include<string>

struct CustomerAccount

{

string customerName;

string customerAddress;

string city;

string state;

int zip_code;

long long telephone;

double accountBalance;

string last_payment_date;

};

int main()

{

int choice, index = 0;

int customerNumber;

struct CustomerAccount accountObject[20];

while (1)

{

cout << endl;

cout << "\n1. Enter new account information" << endl;

cout << "2. Change account information" << endl;

cout << "3. Display all account information" << endl;

cout << "4. Exit the program " << endl;

cout << endl;

cout << "Enter choice :";

cin >> choice;

switch (choice)

{

case 1:

{

cout << "Enter Customer customerName :";

cin >> accountObject[index].customerName;

cin.ignore();

cout << "Enter customerAddress :";

std::getline(std::cin, accountObject[index].customerAddress);

cout << "Enter city :";

cin >> accountObject[index].city;

cout << "Enter state :";

cin >> accountObject[index].state;

cout << "Enter Zip code :";

cin >> accountObject[index].zip_code;

cout << "Enter mobile number :";

cin >> accountObject[index].telephone;

cout << "Enter account Balance :";

cin >> accountObject[index].accountBalance;

cout << "Enter last payment date :";

cin >> accountObject[index].last_payment_date;

index++;

break;

}

case 2:

{


while (1)

{

cout << "Enter customer number :";

cin >> customerNumber;

if (customerNumber < 0 || customerNumber >= index)

{

cout << "Invalid.Must be greater than or equal to 0 and less than " << index << endl;

continue;

}

else

break;

}

cout << endl << endl;

cout << "Customer customerName :" << accountObject[customerNumber].customerName << endl;

cout << "Customer customerAddress:" << accountObject[customerNumber].customerAddress << endl;

cout << "City:" << accountObject[customerNumber].city << endl;

cout << "State:" << accountObject[customerNumber].state << endl;

cout << "Zip code :" << accountObject[customerNumber].zip_code << endl;

cout << "Telephone :" << accountObject[customerNumber].telephone << endl;

cout << "Account accountBalance:" << accountObject[customerNumber].accountBalance << endl;

cout << "Date of last payment:" << accountObject[customerNumber].last_payment_date << endl;

cout << endl << endl;

cout << "Enter customerName :";

cin >> accountObject[customerNumber].customerName;

cin.ignore();

cout << "Enter customer Address :";

std::getline(std::cin, accountObject[customerNumber].customerAddress);

cout << "Enter city :";

cin >> accountObject[customerNumber].city;

cout << "Enter state :";

cin >> accountObject[customerNumber].state;

cout << "Enter Zip code :";

cin >> accountObject[customerNumber].zip_code;

cout << "Enter mobile number :";

cin >> accountObject[customerNumber].telephone;

cout << "Enter accountBalance :";

cin >> accountObject[customerNumber].accountBalance;

cout << "Enter last payment date :";

cin >> accountObject[customerNumber].last_payment_date;

break;

}

case 3:

{


for (int i = 0; i < index; i++)

{

cout << "Customer Name :" << accountObject[i].customerName << endl;

cout << "Customer Address:" << accountObject[i].customerAddress << endl;

cout << "City:" << accountObject[i].city << endl;

cout << "State:" << accountObject[i].state << endl;

cout << "Zip code :" << accountObject[i].zip_code << endl;

cout << "Telephone :" << accountObject[i].telephone << endl;

cout << "Account accountBalance:" << accountObject[i].accountBalance << endl;

cout << "Date of last payment:" << accountObject[i].last_payment_date << endl;

cout << "Press enter to continue..." << endl;

system("PAUSE");

}

break;

}

case 4:

{

cout << "Program Exit" << endl;

exit(0);

}

default:

{

cout << "Invalid input.Must be 1 or 2 or 3" << endl;

break;

}

}

//break;

}

return 0;

}

Sample output:

Add a comment
Know the answer?
Add Answer to:
I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ getline errors I am getting getline is undefined error messages. I would like the variables...

    C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...

  • So I'm not sure what I'm trying to do here. I don't understand how *adr works,...

    So I'm not sure what I'm trying to do here. I don't understand how *adr works, I guess it's a pointer to the struct Address. How do I complete this function? And how would I have it just return the zip code or one element if I wanted to? I have two structs: struct Address {    int number; // street number    string street; // street Name    string city; // city    short zip; // zip code   ...

  • This is for a C++ program: I'm almost done with this program, I just need to...

    This is for a C++ program: I'm almost done with this program, I just need to implement a bool function that will ask the user if they want to repeat the read_course function. I can't seem to get it right, the instructions suggest a do.. while loop in the main function. here is my code #include <iostream> #include <cstring> #include <cctype> using namespace std; const int SIZE = 100; void read_name(char first[], char last[]); void read_course(int & crn, char des[],...

  • I need help modifying this code please ASAP using C++ Here is what I missed on this code below Here are the instruction...

    I need help modifying this code please ASAP using C++ Here is what I missed on this code below Here are the instructions Here is the code Produce correct70 pts O pts Full Marks No Marks results and statisfy requirements view longer Comments 1. Your display amount is not readable 2. I withdraw more than my balance, but I didn't see any error message description Documentations10 pts 0 pts Full Marks No Marks : comment i code and block comment...

  • I need help solving this assignment, you are given a full piece of code that does not run correctly. Some of the bugs ca...

    I need help solving this assignment, you are given a full piece of code that does not run correctly. Some of the bugs can be found at compile time, while others are found at run time. Access the UserMenu.cpp code file (in the zip file in Start Here) and use debugging practices and the debugger in Visual Studio to find each bug. Fix the bug and write a comment in the code giving a description of how you found the...

  • Hello, I have some errors in my C++ code when I try to debug it. I...

    Hello, I have some errors in my C++ code when I try to debug it. I tried to follow the requirements stated below: Code: // Linked.h #ifndef INTLINKEDQUEUE #define INTLINKEDQUEUE #include <iostream> usingnamespace std; class IntLinkedQueue { private: struct Node { int data; Node *next; }; Node *front; // -> first item Node *rear; // -> last item Node *p; // traversal position Node *pp ; // previous position int size; // number of elements in the queue public: IntLinkedQueue();...

  • I don't know how to terminate the code in the second time that whether or not...

    I don't know how to terminate the code in the second time that whether or not the users want to continue to get a new number. PLEASE HELP. To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number 438-5626 can be shown as GET LOAN. In some cases, to make a telephone number meaningful, companies might use more than seven letters. For example, 225-5466 can be displayed...

  • C++ language I need to update this code with the following: ask the user for how...

    C++ language I need to update this code with the following: ask the user for how many structures they would like. Once you get the number, allocate an array of pointers. Once they have been created, proceed to loop through and get the data as usual, and display it back to the screen. struct record {    int age;    string name; }; int check(record r[], int n, string nm) {    for (int i = 0; i < n;...

  • Help with C++ reverse program with leading zeros. I need to put the line from the...

    Help with C++ reverse program with leading zeros. I need to put the line from the function that display the zeros in main not in the function. So how can I move the display with leading zeros in main. Thanks. Here is my code. #include <iostream> #include <cstdlib> #include <iostream> using std::cout; using std::cin; using std::endl; //function templates int reverseNum(int); int main() { //variables char buf[100]; int num; while (true) { //prompt user for input cout << "Enter the number...

  • I need to be able to input first and last name. My code only outputs first...

    I need to be able to input first and last name. My code only outputs first when you put 2 names. This is not my full code. Any type of help wou;d be great! int main() { int main_choice; int grade_choice; int std_id; int new_grade; char g_name[100]; char s_name[100]; float a,b,c; gradebook g; do { cout <<endl; cout<< " -=| MAIN MENU |=-" << endl; cout<< "1. Add a student" << endl; cout << "2. Remove a student" << endl;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT