#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
struct productJewelry
{
string name;
double amount;
int itemCode;
double size;
string group;
};
int main()
{
// declare variables
ifstream inFile;
int count=0;
int x=0;
productJewelry product[50];
inFile.open("jewelry.txt"); // file must be in same folder
if (inFile.fail())
cout << "failed";
cout << fixed << showpoint; // fixed format, two decimal places
cout << setprecision(2);
while (inFile.peek() != EOF)
{
// cout << count << " : ";
count++;
inFile>> product[x].itemCode;
inFile>> product[x].name;
inFile>> product[x].size;
inFile>> product[x].amount;
inFile>> product[x].group;
// cout << product[x].itemCode << ", " << product[x].name << ", "<< product[x].size << ", " << product[x].amount << endl;
x++;
if (inFile.peek() == '\n')
inFile.ignore(1, '\n');
}
inFile.close();
string temp;
bool swap;
do
{
swap = false;
for (int x=0; x<count;x++)
{
if (product[x].name>product[x+1].name)
{
//these 3 lines are to swap elements in array
temp=product[x].name;
product[x].name=product[x+1].name;
product[x+1].name=temp;
swap=true;
}
}
} while (swap);
for (x=0; x< count; x++)
{
//cout<< product[x].itemCode<<" ";
//cout<< product[x].name <<" ";
//cout<< product[x].size <<" ";
//cout<< product[x].amount<<" ";
//cout<< product[x].group<<" "<<endl;
}
system("pause"); // to freeze Dev-c++ output screen
return 0;
} // end main
views:
40answers:
1
+1
A:
It says "press any key to continue" because that's what the pause program invoked by system("pause") does.
It doesn't output anything else because you've commented out all of the output statements.
Tyler McHenry
2010-05-07 14:17:12