Hey everyone :) Hope you can help
Here is what I've done with the instructions given:
I need to know the average price difference between the cash and credit prices. But i'm pretty sure that only comes in at the end. Here is what my this function is supposed to do:
determine the difference between the cash price and credit price for an item and add this difference to the total of the differences. So what I've done below seems pretty basic to me- but I'm guessing this must be the error based on what I try to do with the code later on.]
void updateDifference(float cashPriceP, float creditPriceP, float & totalOfDifferencesP)
{
float difference;
difference = cashPriceP - creditPriceP;// This is probably wrong
totalOfDifferencesP += difference;
}
Here is the main function:
int main()
{
for (int i= 1; i <= NR_ITEMS; i++)
{
string description;
int shelfStay;
float wholesalePrice, cashPrice, creditPrice, totalOfDifferences, averagePriceDifference;
// initialise total
totalOfDifferences = 0;
inputAndValidate(description, shelfStay, wholesalePrice);
determinePrices(shelfStay,wholesalePrice, cashPrice, creditPrice);
updateDifference(cashPrice, creditPrice, totalOfDifferences);
cout.setf(ios::fixed);
cout.precision(2);
cout << description << " is expected to stay on the shelf for " << shelfStay << " days and has a wholesale price"
<< endl << " of "
<< "R" << wholesalePrice << endl;
cout << " The cash price for " << description << " is R" << wholesalePrice << endl;
cout << "The total of the difference between the cash and credit" << endl;
cout << " prices is now R " << updateDifference << endl;
// updateDifference always gives me the same result which is R1 - so of course the average of the six items I enter will always be R1- this is obviously very wrong and that's why I say above that my function updateDifference must be the error.
}
//averagePriceDifference += updateDifference;
//averagePriceDifference /= 6;// I want to put these 2 lines in the loop above but my compiler complains
//cout << "The average price difference between the cash and credit prices is: " << endl;
//cout << averagePriceDifference << endl;
system("pause");
return 0;
}
I'd love it if you could just point out any flaws you see in this piece of code. Thanks :)