Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help C++. A code analysis says When executed, your code tried to create an

ID: 3868782 • Letter: N

Question

Need help C++.

A code analysis says

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.

#include <iostream>

#include <string>

using namespace std;

struct customer

{

string name, address, city, state, zip, telephone, date;

int balance;

};

void setCustomer(customer&);

void getCustomer(customer);

int main()

{

int size, action = 1;

cout << "*** Customer Accounts *** How many customers?: ";

cin >> size;

customer*database = new customer[size];

cout << " --- Create database of " << size << " customer(s)--- ";

while(action!=3)

{

cout << "** Menu ** (1) Enter account information (2) Display all account information (3) Exit the program >";

cin >> action;

cout << endl;

switch(action)

{

case 1:

{

int cnum;

cout << "customers: ";

for (int x = 0; x < size; x++)

cout << x + 1 << " : " << database[x].name << endl;

cout << " custmer number to change: ";

cin >> cnum;

if (cnum <= size && cnum > 0)

setCustomer(database[cnum - 1]);

else

cout << " invalid customer number! ";

}

break;

case 2:

{

int cnum;

cout << "customers: ";

for (int x = 0; x < size; x++)

cout << x + 1 << " : " << database[x].name << endl;

cout << " Enter customer number to display: ";

cin >> cnum;

if(cnum<=size && cnum>0)

getCustomer(database[cnum - 1]);

else cout << " invalid customer number! ";

}

break;

default: break;

}

}

delete[] database;

return 0;

}

void setCustomer(customer&set)

{

cout << "Enter Data for the Customer: Name: ";

cin >> set.name;

cout << "Address: ";

cin.ignore(256, ' ');

getline(cin, set.address);

cout << "City: ";

cin >> set.city;

cout << "State: ";

cin >> set.state;

cout << "Zip Code: ";

cin >> set.zip;

cout << "Telephone Number: ";

cin >> set.telephone;

cout << "Date of last Payment: ";

cin >> set.date;

do

{

cout << "Account Balace: ";

cin >> set.balance;

if (set.balance < 0)

cout << "Invalid Balace! ";

}

while (set.balance < 0);

}

void getCustomer(customer get)

{

cout << " --- Data for" << get.name << " --- ";

cout << " Address: " << get.address << "," << get.city << "," << get.state << "," << get.zip;

cout << " Telephone:|t" << get.telephone;

cout << " Last Payment: " << get.date;

cout << " Account balance: " << get.balance << endl << endl;

}

Explanation / Answer

Checked the program and executed it.
All the loops (for and while seems fine). No existence of any infinite loop.
Overall Program runs fine.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote