Stock Sorter

I'm supposed to make a program which reads a txt file containing stock names and prices and then put them into a struct and then sort it. It's only been like 6 weeks since this class started so I'm pretty overwhelmed with this assignment.

I tried using the ifstream inClientFile to read the text file I made but I can't seem to get it to read it let alone turn the data into structs and sort it. Can someone offer some guidance on what to do?

Thanks
Well, the solution is probably going to involve some sort of 'stock' structure containing a string and a number, and then it's most likely going to open the file in a stream, then use some sort of loop to put that data into your structures. What is the code that you have that isn't working?
Well now i'm just trying to manually add each struct but I can't get it to work. For example

using namespace std;

float Return;
float RETURNS( float p1, float p2) //calculates the return
{
Return = (p2 - p1)/p1;
return Return;
}

struct stock{ //builds the overall struct
char name[150];
float price1;
float price2;
float Return;
};



stock list[10]; //our stocks values
strcmp(list[1].name,"AT&T");
list[1].price1 = 4.50;
list[1].price2 = 5.50;
list[1].Return = RETURNS(list[1].price1,list[1].price2);

strcmp(list[2].name,"FAB");
list[2].price1 = 10.50;
list[2].price2 = 11.20;
list[2].Return = RETURNS(list[2].price1,list[2].price2);
Topic archived. No new replies allowed.