Supplier Directory Project Question

Hi guys, I'm new to C++ Programming and as a requirement to a certain subject we are tasked to make a work related program. So i decided to make a supplier directory program. I wanted the program to take data from a text file.
So the main problem that i encounter is, i don't know what the text file format should be so it can read another data from another supplier, also is it possible to have a scope with multiple suppliers?
Thanks in advance

Here's my source code:

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

int main()
{
ifstream inFile1;
string Scope;
string cname;
string cperson;
string cnumber;
string Scopedoc;
string cnamedoc;
string cpersondoc;
string cnumberdoc;
int playagain;

inFile1.open("TelephoneDirectory.txt");
//exit if file cannot be opened
if (!inFile1)
{
cout <<"Cannot open input file."<<endl;
return 0;
}

//Order of data from file
inFile1 >>Scopedoc >> cnamedoc >> cpersondoc >> cnumberdoc;
do
{
//Ask user to enter scope of work.
cout<<"Please enter the scope / nature of work: " <<endl;
cin>> Scope;

{
//inFile1 >>Scopedoc >> cnamedoc >> cpersondoc >> cnumberdoc;
if( Scope == Scopedoc)
cout<< "Company Name: \n" << cnamedoc<< "\nContact Person: \n" << cpersondoc<< "\nContact Number: \n" << cnumberdoc <<endl;
else
cout<<"Number was not in directory."<<endl;
}
cout <<"Want to continue looking? 0 for no, 1 for yes. " <<endl;
cin >>playagain;
}
while (playagain == 1);


system("PAUSE");
return 0;

}

and here is what my text file has:

Tiles FloorToGo Hans 09351864545 |
ToiletPartition Jebsen RA 09564875560 |
Lockset Dorma Steve 09546556123 |
Tiles Itrade Sandy 09224568916 |

Hope you guys can help me.
So the main problem that i encounter is, i don't know what the text file format should be so it can read another data from another supplier


Do you mean you want to list the same product from 2 suppliers? Such as, Tiles can come from, for instance, FloorToGo and Jebsen? In that case, just have 2 lines in your data file for Tiles.

Tiles FloorToGo Hans 09351864545 |
Tiles Jebsen RA 09564875560 |
ToiletPartition Jebsen RA 09564875560 |
Lockset Dorma Steve 09546556123 |
Tiles Itrade Sandy 09224568916 |

also is it possible to have a scope with multiple suppliers


I guess I answered that above.

The code you posted merely checks the first entry in the file. If it matches the scope, it prints out the values. Note that playagain is not initialized at this point.

If the scope does not match, the program asks if you want to play again and takes an int as input. I'll assume you enter an int (because you are not handling erroneous input at all).

At this point, if the playagain value happened to be initialized to 1 (if first line contained your scope) or if the user entered 1 (if the first line did not contain your scope), the program loops up and asks for a new scope.

At NO TIME does you program look at anything beyond the first line of your file. You are not looping through the lines of the file. If you want to print out all suppliers for a specific scope, loop through the entire file and print out all entries that match what you want.
I recommend separating the fields with a unique char such as what you did at the end of the line.

Such as
Tiles | FloorToGo | Hans |09351864545

Allows you to use spaces such as
Tiles, wall | Floor To Go | Hans LastName |09351864545
Tiles, floor | Floor To Go | Hans LastName |09351864545
At NO TIME does you program look at anything beyond the first line of your file. You are not looping through the lines of the file. If you want to print out all suppliers for a specific scope, loop through the entire file and print out all entries that match what you want.


Hi can you give me any idea how to loop through the entire file?
Your response is highly appreciated.
Topic archived. No new replies allowed.