Just will not work!

Pages: 12
That is incredible, you cannot imagine how awesome that sounds to me. Thank you again for the help.
closed account (48T7M4Gy)
4444 150 150 0 45.00 125.00
Circular Saw
3333 50 50 20 450.00 850.00
Cooking Range

This is a small embellishment on Handys suggestion where getline is useed on the second line.

Enclosing the two words in quotes makes them a single string too if your input file is able to be modified. "Cooking range"

Another situation arises if it is always two words. You can take advantage of that regularity too. This would be the simplest of the lot and not altogether unreasonable.
Last edited on
If you have the item on one line you can read it like that:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <fstream>  
#include <string>   
#include <vector>  
#include <iomanip> 

using namespace std;  

const int invSize = 2;  

void getInventory(ifstream& infile, vector<string>& itemID, 
                  vector<string>& itemName, vector<int>& pOrdered,   
                  vector<int>& pInStore, vector<int>& pSold, 
                  vector<double>& manufPrice, vector<double>& sellingPrice);  

void printInventory(vector<string>& itemID, vector<string>& itemName, 
                 vector<int>& pOrdered, vector<int>& pInStore, 
                 vector<int>& pSold, vector<double>& manufPrice,   
                 vector<double>& sellingPrice);  


int main()  
{  
  vector<int> itemQuantity(invSize);  
  vector<string> itemID(invSize);  
  vector<string> itemName(invSize);  
  vector<int> pOrdered(invSize);  
  vector<int> pInStore(invSize);  
  vector<int> pSold(invSize);  
  vector<double> manufPrice(invSize);  
  vector<double> sellingPrice(invSize);  
  ifstream infile("inventory.txt");  
  if (!infile)  
  {  
    perror("File error: ");
    system("pause");
    return 1;  
  }  
  getInventory(infile, itemID, itemName, pOrdered, pInStore, pSold, manufPrice, sellingPrice);  
  printInventory(itemID, itemName, pOrdered, pInStore, pSold, manufPrice, sellingPrice);
  
  system("pause");
  return 0;  
}  

//  itemId, pOrdered, pInStore, pSold, manufPrice, sellingPrice, itemName. 
void getInventory(ifstream& infile, vector<string>& itemID, 
                  vector<string>& itemName, vector<int>& pOrdered,   
                  vector<int>& pInStore, vector<int>& pSold, 
                  vector<double>& manufPrice, 
                  vector<double>& sellingPrice)  
{  
  unsigned int i = 0;  
  string line; 
   
  for (i = 0; i < invSize; i++)  
  {  
    infile >> itemID[i]
           >> pOrdered[i]   
           >> pInStore[i]
           >> pSold[i]
           >> manufPrice[i]   
           >> sellingPrice[i];  
    getline(infile, itemName[i]);
    
  }
 
}  
void printInventory(vector<string>& itemID, vector<string>& itemName, vector<int>& pOrdered,    
  vector<int>& pInStore, vector<int>& pSold, vector<double>& manufPrice,   
  vector<double>& sellingPrice)  
{  
  cout << "Friendly Hardware Store inventory" << endl << endl;  
  for (int i = 0; i < invSize; i++)  
  {  
    cout << "\nItem ID: "   << itemID.at(i);  
    cout << "\nItem name:"  << itemName.at(i);  
    cout << "\nOrdered: "   << pOrdered.at(i);  
    cout << "\nIn store: "  << pInStore.at(i);  
    cout << "\nSold: "      << pSold.at(i);  
    cout << "\nManufactoring price: " << manufPrice.at(i);  
    cout << "\nSelling price: " << sellingPrice.at(i);
    cout << "\n" << string(60, '=') << '\n';
  }  
}

Input:
1
2
4444 150 150 0 45.00 125.00 Circular Saw
3333 50 50 20 450.00 850.00 Cooking Range


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Friendly Hardware Store inventory


Item ID: 4444
Item name: Circular Saw
Ordered: 150
In store: 150
Sold: 0
Manufactorin price: 45
Selling price: 125
============================================================

Item ID: 3333
Item name: Cooking Range
Ordered: 50
In store: 50
Sold: 20
Manufactorin price: 450
Selling price: 850
============================================================
Press any key to continue . . .
Thomas1965, it works, I can't believe I am seeing this thing work! Thank you , thank you all so much. This is going to be the best day!
kemort wrote:
Enclosing the two words in quotes makes them a single string too if your input file is able to be modified. "Cooking range"

Please explain. In
1
2
3
4
5
6
7
8
#include <iostream>
#include <string>
int main() {
  std::string foo;
  std::cin >> foo;
  std::cout << foo;
  return 0;
}

with input:
"hel lo"

the output is:
"hel


}
closed account (48T7M4Gy)
Nothing to explain, it doesn't work.
Not to worry, you did try. I can see that. The list from Thomas1965 works fine and all I have to do now is rewrite the search, print, and sell functions. I am pretty sure I can handle the first two, but to be honest I am not even sure where to start with the sell function. No worries, I will figure it out before tomorrow night. I have to say once more how thankful I am for the help all of you have given me. Thank you all.
greengirl1968,

Good to hear that you have made progress. The search, sell and ring functions from the original code are good. they just need a little tweaking and maybe some formatting of the output. I managed to get them all working yesterday and it works well.

Good job,

Andy
I am surprised to hear those functions work at all. I was convinced they were hopeless, if you say they need tweaking, then tweaking I will attempt to do. It sounds better than starting all over with them. Thanks.
Topic archived. No new replies allowed.
Pages: 12