I am having some trouble with an assignment where I need to generate a file of a database composed of structures in an array. Currently, when the selection is made to print the table no noticeable error occurs, but the code produces no file. (Apologies if this is messy, still new to the site)
This is my current code
Prototypes:
void ordertable_disp( item s[], int size);
void print_ordertable_disp(item s[], int size);
Table Function :
void ordertable_disp(item s[], int size)
{
int counter = 0;
int BookOrder = 0;
int enroll = 0;
double AllOrders = 0.0;
double OrderFactor = 0.0;
double total_value = 0.0;
double bprice = 0.0;
string resp = "XXX";
system("cls");
cout << endl;
cout << " COLLEGE BOOK ORDERING SYSTEM" << endl;
cout << endl;
cout << " Book Order Table" << endl;
cout << endl;
cout << endl;
cout << setw(40) << "Book Title" << " " << setw(15) << "ISBN" << " " << setw(20) << "Author" << " " << setw(19) << "Expected Enrollment" << " " << setw(17) << "Book Cost (Price)" << " " << setw(9) << "Required" << " " << setw(7) << "Unused" << endl;
cout << setw(40) << "----------" << " " << setw(15) << "----" << " " << setw(20) << "------" << " " << setw(19) << "-------------------" << " " << setw(17) << "-----------------" << " " << setw(9) << "--------" << " " << setw(7) << "------" << endl;
for(counter = 0; counter < size; counter++)
{
cout << setw(40) << s[counter].BookTitle << " " << setw(15) << s[counter].ISBN << " " << setw(20) << s[counter].Author << " " << setw(19) << s[counter].EXPenroll << " " << setw(17) << s[counter].price << " " << setw(9) << s[counter].reqNreq << " " << setw(7) << s[counter].UsedUnused << endl;
if((s[counter].reqNreq== "Y") || (s[counter].reqNreq== "y"))
{
if((s[counter].UsedUnused== "Y") || (s[counter].UsedUnused== "y"))
{
OrderFactor= 1.0; // Book is new and required
}
else
{
OrderFactor= 0.60; // Book is used and required
}
}
else // Order factor calculation
{
if((s[counter].UsedUnused== "Y") || (s[counter].UsedUnused== "y"))
{
OrderFactor= 0.35; // Book is new and not required
}
else
{
OrderFactor= 0.10; // Book is used and not required
}
}
enroll = atoi(s[counter].EXPenroll.data());
BookOrder= OrderFactor * enroll;
bprice = atof(s[counter].price.data());
total_value = total_value +(total_value = bprice * BookOrder);
} cout << " Total Order Value: " << total_value << endl;
cout << " Would You Like To Print This Table(Y/N): "; getline(cin, resp);
if(toupper(resp.at(0))=='Y')
void print_ordertable_disp(item s[], int size);
system("cls");
}
print function :
void print_ordertable_disp(item s[], int size)
{
ofstream ofile;
ofile.open("Sample2.prn");
int counter = 0;
int BookOrder = 0;
int enroll = 0;
double AllOrders = 0.0;
double OrderFactor = 0.0;
double total_value = 0.0;
double bprice = 0.0;
system("cls");
ofile << endl;
ofile << " COLLEGE BOOK ORDERING SYSTEM" << endl;
ofile << endl;
ofile << " Book Order Table" << endl;
ofile << endl;
ofile << endl;
ofile << setw(40) << "Book Title" << " " << setw(15) << "ISBN" << " " << setw(20) << "Author" << " " << setw(19) << "Expected Enrollment" << " " << setw(17) << "Book Cost (Price)" << " " << setw(9) << "Required" << " " << setw(7) << "Unused" << endl;
ofile << setw(40) << "----------" << " " << setw(15) << "----" << " " << setw(20) << "------" << " " << setw(19) << "-------------------" << " " << setw(17) << "-----------------" << " " << setw(9) << "--------" << " " << setw(7) << "------" << endl;
for(counter = 0; counter < size; counter++)
{
ofile << setw(40) << s[counter].BookTitle << " " << setw(15) << s[counter].ISBN << " " << setw(20) << s[counter].Author << " " << setw(19) << s[counter].EXPenroll << " " << setw(17) << s[counter].price << " " << setw(9) << s[counter].reqNreq << " " << setw(7) << s[counter].UsedUnused << endl;
if((s[counter].reqNreq== "Y") || (s[counter].reqNreq== "y"))
{
if((s[counter].UsedUnused== "Y") || (s[counter].UsedUnused== "y"))
{
OrderFactor= 1.0; // Book is new and required
}
else
{
OrderFactor= 0.60; // Book is used and required
}
}
else // Order factor calculation
{
if((s[counter].UsedUnused== "Y") || (s[counter].UsedUnused== "y"))
{
OrderFactor= 0.35; // Book is new and not required
}
else
{
OrderFactor= 0.10; // Book is used and not required
}
}
enroll = atoi(s[counter].EXPenroll.data());
BookOrder= OrderFactor * enroll;
bprice = atof(s[counter].price.data());
total_value = total_value +(total_value = bprice * BookOrder);
} ofile << " Total Order Value: " << total_value << endl;
ofile.close();
}
In this section of code:
cout << " Would You Like To Print This Table(Y/N): "; getline(cin, resp);
if(toupper(resp.at(0))=='Y')
void print_ordertable_disp(item s[], int size);
you seem to be redeclaring the function signature instead of calling the function.
This should look something like:
cout << " Would You Like To Print This Table(Y/N): "; getline(cin, resp);
if(toupper(resp.at(0))=='Y')
print_ordertable_disp(s, size);
notice I've removed the keyword void
and passed along s
and size
rather than redefining them.
I think that's most likely to be where your problem starts.