#include <cstdlib>
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
struct Item
{
string name;
int quantity;
double unitPrice;
string description;
};
struct ItemTotal
{
string name;
int quantity;
double unitPrice;
string description;
};
void sort(Item list[], int n)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n-i-1;j++)
if (list[j].description<list[j+1].description)
swap(list[j],list[j+1]);
}
}
void display(Item a[], int size)
{
for(int i = 0; i < size; i++)
cout << a[i].name << " " << a[i].quantity << " " << a[i].unitPrice << "\n";
cout << "\n";
}
void swap(Item& c1, Item& c2)
{
Item temp = c1;
c1 = c2;
c2 = temp;
}
int main(int argc, char *argv[])
{
string infilename,outfilename;
ifstream infile;
char inFileName[20],outFileName[20];
do
{
infile.clear();
cout<<"Please enter file containing details of items: "<<flush;
cin>>inFileName;
infile.open(inFileName);
} while(!infile.good());
cout<<"Please enter output file: "<<flush;
cin>>outFileName;
ofstream outfile;
outfile.open(outFileName);
string line;
getline(infile,line);
Item Item1[10];
for(int i=0;i<10;i++)
{
infile>>Item1[i].name;
for (int k=0;k<5;k++)
infile>>Item1[i].unitPrice[k];
Item1[i].quantity=0;
for(int j=0;j<4;j++)
{ Item1[i].quantity+=Item1[i].unitPrice[j];
Item1[i].quantity+=Item1[i].unitPrice[4]/2;
}
}
for(int i=0;i<10;i++)
outfile<<setw(10)<<setfill(' ')<<left<<Item1[i].name<<setw(10)<<setfill(' ')<<right<<"- "<<fixed<<setprecision(2)<<Item1[i].quantity<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
singhraghav
-6
Newbie Poster
Salem
commented:
you have 17 posts, and haven't figured out code tags
-6
Recommended Answers
Jump to PostCan anyone please find whats wrong in this code
Yes. It doesn't compile and therefore won't work.
Jump to PostUse code tags.
You have given us nothing to go on here, does the compiler throw errors at you? Is the output wrong or not what you expected?
Remember, a decent question gives a decent answer.
All 5 Replies
Nick Evan
4,005
Industrious Poster
Team Colleague
Featured Poster
William Hemsworth
1,339
Posting Virtuoso
kvprajapati
1,826
Posting Genius
Team Colleague
Topi Ojala
2
Junior Poster in Training
mirfan00
-19
Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.