Thanks for all the help, I got it to do what I needed
I chose C++ since it is the only language I know. The first two and a half years of college I studied computer science where they taught us C++. Then I switched to mathematics. That was about 7 years ago. Now I'm working at my dad's hydraulic repair shop doing misc stuff and I thought it would be a nifty idea to be able to price out a hose assembly with just inputting hose number.
The first part was to take the input as a string and break it down into the components and store them as strings, as such:
Enter Hose Assembly Number
>>F3020639060808-12
302-8 (Hose type & size)
10643-6-8 (hose end 1)
13943-8-8 (hose end 1)
The next part was the part that I was stuck on. I wanted to search a simple text file for the components and store the price next to it as a float. I wanted to use a text file just for the fact it was simple. I could copy & past the data from our database into the text file.
But thanks to
find() was able to scan the file and locate the component, then with
substr() I was able to extract the data I needed, and then with
istringstream I converted the price from a string to a float.
Here's the code I came up with:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
string line;
string price_str;
float price = 0.0;
string hose_end ("10643-8-8") //just to test it;
ifstream hose_file("hose.txt");
if (hose_file.is_open())
{
while (! hose_file.eof() )
{
getline (hose_file,line);
if(line.find(hose_end) != string::npos)
{
cout << line << endl;
price_str = line.substr(hose_end.length(),line.length()-hose_end.length());
istringstream iss(price_str);
iss >> price;
cout << price;
}
}
hose_file.close();
}
else cout << "Unable to open file";
|
Once again, thank for those who helped