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
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
#include
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?:\t";
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:\t";
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:\t";
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:\t\t\t";
cin >> set.name;
cout << "Address:\t\t";
cin.ignore(256, ' ');
getline(cin, set.address);
cout << "City:\t\t\t";
cin >> set.city;
cout << "State:\t\t\t";
cin >> set.state;
cout << "Zip Code:\t\t\t";
cin >> set.zip;
cout << "Telephone Number:\t";
cin >> set.telephone;
cout << "Date of last Payment:\t";
cin >> set.date;
do
{
cout << "Account Balace:\t";
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:\t" << get.address << "," << get.city << "," << get.state << "," << get.zip;
cout << " Telephone:|t" << get.telephone;
cout << " Last Payment:\t" << get.date;
cout << " Account balance:\t" << get.balance << endl << endl;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started