0

The following code will not take an input for the itemId and skips straight the item description. I don't why I've been trying to look up stuff for several hours now and have had no luck.

void AddRecord(fstream &file, string name)
{
    file.open(name, ios::app);

    int  quanity;
    string itemId;
    string itemDes;
    float wholeCost, retailCost;

    cout << "What is the ID of this item? ";
    getline(cin, itemId);
    file << itemId << endl;\
    cin.clear();

    cout << "\nInsert an item description. ";
    getline(cin, itemDes);
    cin.clear();
    file << itemDes << endl;

    cout << "\nHow many do you have? ";
    cin >> quanity;
    file << setprecision(2) << quanity << endl;

    cout << "\nWhat is the whole sale cost? ";
    cin >> wholeCost;   
    while ( wholeCost > 57.14 )
    {
        cout << "\nWhat is the wholesale cost? ";
        cin >> wholeCost;
    }
    file << setprecision(2) << wholeCost << endl;

    cout << "\nWhat is the retail cost? ";
    cin >> retailCost;
    while ( retailCost > (1.75 * wholeCost) )
    {
        cout << "\nWhat is the retail cost? ";
        cin >> retailCost;
    }
    file << setprecision(2) << retailCost << endl << endl;

    file.close();
}
rmunn
  • 29,094
  • 9
  • 62
  • 91

0 Answers0