Start New Discussion within our Software Development Community

I'm having a problem with the if loop. My program should display a warning sign and skip an incomplete a bad record the user has enter that otherwise would have been displayed in an invoice.

for example: if the user enters the following 3 lines when reading purchased items
o P010001 2 whatever
o P010002
o 1
the "whatever" bits there will be ignored because a purchased item record just needs the first 2 fields, the productId P010001 and the quantity 2, so the rest of the same line is ignored. The next 2 lines actually contain 2 bad item records because each single line contains an incomplete record and is thus considered an invalid record. The program should skip such bad records with a warning message.

This is what i did

while (option == "\\ItemPrice")
      cerr << "Enter ItemId followed by space and then price or \\ItemOrder to end this list: ";
      cin >> item;
        if (item == "ItemId" && item == "price")
    cin>> item;
    cerr << "Warning: This record is incomplete"//take a new line 
    << "\n""Enter ItemId followed by space and then price or \\ItemOrder to end this list:"

But it seems that the statement i wrote in the if brackets is wrong as my program displays the warning message even though i enter the full record.

Please give me an idea of what i should write in the brackets and please tell me if i'm using the wrong loop.

According to the spacing of the code you posted it is missing a close bracket } after line 8 and before line 10 so that lines 1 thru 8 are contained within the if statement starting on line 1.

This article has been dead for over six months. Start a new discussion instead.