hello
I have some code that loops & takes in a number then should store it in an array.
My problem is that for some reason, the program only stores every 2nd number entered?
while (!cin.fail() && cin>>purchase) { // while a correct input is input
cin >> purchase; // enter recent purchase
pur[nWeek][counter] = purchase; // store recent purchase in relevent array element
cout << "purchase put in array element " << counter << "\n";
counter++;
}
Whole function
void enterPurchase(float pur[][25], int nWeek, int counter) {
float purchase = 0;
while (!cin.fail() && cin>>purchase) { // while a correct input is input
cin >> purchase; // enter recent purchase
pur[nWeek][counter] = purchase; // store recent purchase in relevent array element
cout << "purchase put in array element " << counter << "\n";
counter++;
}
for (int i=0; i<counter; i++) {
cout << "Purchase No." << (i+1) << ": $";
cout << pur[nWeek][i] << "\n";
}
cout << pur[nWeek][2] << endl;
}