Pseudo code

Write a program that prompts the user to enter an item#, the program should determine if the item is in the file and print the price of the corresponding item. If the item is not in the file an error message should be printed.

All I have so far is

string item_no=0;

cout<<"Enter a item#";
getline(cin,item_no);

if stream openData;

I need to finish the rest in pseudo code
Without the format of the file, it's difficult to answer this question, but assuming the file looks like:
123 53.63 // item number cost

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
int item_no = 0; // we'll use int because it will automatically convert
cout << "Enter an item#" << endl;

cin >> item_no;

// search for the item number in the file
ifstream inFile("filename");

while (inFile)
{
    // get the item number and cost
    int fileItemNumber = 0;
    inFile >> fileItemNumber;

    // get the cost
    double itemCost = 0;
    inFile >> itemCost;

    //Check if they're equal, if so we're done
    if(fileItemNumber == item_no)
    {
        cout << "Cost: " << itemCost << endl;
        return 0; // exit the program
    }

    // if we get here then the item is not in the file
    cout << "Error: Item not found in file: " << "file name" << endl;
    return 0;
}
Hey, please try not to double post. This was already posted by you in this same thread a couple hours ago here: http://www.cplusplus.com/forum/general/105280/

And I already responded with some pseudocode as well. By double posting it's gonna be hard for people to track the progress of your problem because answers are going to be split between the two threads.
Topic archived. No new replies allowed.