bookSales2_LindsayLewis.cpp: In function `void obtainInput()':
bookSales2_LindsayLewis.cpp:43: error: name lookup of `i' changed for new ISO `for' scoping
bookSales2_LindsayLewis.cpp:39: error: using obsolete binding at `i'
So if we look at this:
Code:
void obtainInput()
{
ifstream fp;
int books;
char shipping_method;
float price;
float subtotal;
float shipping_price;
for (int i=0; i<=books; i++)
fp >> books;
fp >> shipping_method;
for (int i=0; i <= books; i++)
{
fp >> price;
}
subtotal+=price[i];
return subtotal;
if (shipping_method == 'S')
shipping_price = 4.99;
else
shipping_price = 12.99;
}
Let me insert some braces to show you what this means.
Code:
void obtainInput()
{
ifstream fp;
int books;
char shipping_method;
float price;
float subtotal;
float shipping_price;
for (int i=0; i<=books; i++) {
fp >> books;
}
fp >> shipping_method;
for (int i=0; i <= books; i++)
{
fp >> price;
}
subtotal+=price[i];
return subtotal;
if (shipping_method == 'S')
shipping_price = 4.99;
else
shipping_price = 12.99;
}
So i only exists in between those two braces. And then there is another for loop that only loops one statement. Later, you use the obsolete i ...
bookSales2_LindsayLewis.cpp:43: error: invalid types `float[int]' for array subscript
Code:
float price;
subtotal+=price[i];
... as a subscript for a variable that isn't an array.
It looks like your i counters should not be used, because you read most of the information related to a receipt into other variables one item at a time. You might loop price five times, but you have to add it to the subtotal, too, each time. The computer isn't going to remember price's value for the ith iteration after the ith iteration automatically. It would take more memory.
In general, I think your for loops are too small, and you need to brace what they should control. Otherwise, the logic will be different at run time, then what you expect (in addition to compile time errors).
Code:
if( fp >> books >> shipping_method ) {
for ( int i = 0; i < books; i++ ) {
if( fp >> price ) {
subtotal += price;
}
}
}
The branching being there to help you with handling reading errors of course.
Another frankly disturbing problem is that some functions are listed as returning void but they clearly return things. You really should use return values properly.
EDIT:
Also, you have errors related to undefined variables. You can rewrite some functions to define them.
Code:
void displaySummary(float tax, float subtotal, float discount, float total)
{
cout << "The summary for the order is as follows:" << endl;
cout << fixed << showpoint << setprecision (2);
cout << "Subtotal:" << subtotal << endl;
cout << fixed << showpoint << setprecision (2);
cout << "Tax:" << tax << endl;
cout << fixed << showpoint << setprecision (2);
cout << "Discount:" << discount << endl;
cout << fixed << showpoint << setprecision (2);
cout << "Shipping:" << shipping_price << endl;
cout << fixed << showpoint << setprecision(2);
cout << "Total:" << total << endl;
}
There should be items you can pass in to complete calculateOutput() as well.