Access File Program

Creating a program that takes the current info inside of my file and displays it on screen, should display the name of the product, it's quantity, and price next to each other which I have working as it's just taking that data from the file and displaying it, but I need to also make it display the quantity of each object times the price, and displaying it to the right, which I don't know how to do nor can I figure it out.

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
 // Chapter 14 ex. 25.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <fstream>
#include <string>
using namespace std;


int quantXprice(double value);
int main()
{
	ifstream inFile("Advanced25.cpp");

	string name;
	int quantity;
	double price;
	double total;

	cout << "Name" << "\t" << "Quantity" << "\t" << "Price" << "\t" << "Value" << endl;

	while(inFile >> name >> quantity >> price)
	{
		cout << name << "\t" << quantity << "\t" << price << "\t" << quantXprice(value) << endl;
	}
	system("PAUSE");
	return 0;
}
int quantXprice(double value)
{
	ifstream stream;

	stream.open("Introductory21.txt");

	while (!stream.fail())
	{
		
	}
	stream.close();
}


Access file contains
1
2
3
4
5
Watch#400#55.54
Ring#550#99.99
Bracelet#600#20
Earrings#100#10.99
Pins#10#24.35 
How about:
1
2
3
4
5
6
7
8
9
10
11
#include <sstream> // for istringstream
...
string line;
while (getline(inFile, line)) {
    istringstream iss(line);
    getline(iss, name, '#');
    iss >> quantity;
    iss.get();
    iss >> price;
    // ...
}

Last edited on
cout << name << "\t" << quantity << "\t" << price << "\t" << quantity * price << endl;
Topic archived. No new replies allowed.