Where is the error? (driving me nuts!)

My compiler (VisualStudio) is telling me that there is an error on the 40th line. Specifically, it is telling me that a semi-colon was expected. I know that all of the libraries i've included arent necessary, but I've been leaving them at the top just so I dont need to write them every time. I've tried the program with only iostream. That hasn't worked either.

I've copied this program straight out of the Absolute C++ book by W. Savitch.

Edit: the error is on the 37th line. Visual studio highlights this line in red.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <fstream>
using namespace std; 

double totalCost(int numberParameter, double priceParameter);
// Computes the total cost, including 5% sales tax,
// on numberParameter items at a cost of priceParameter each,


int main()
{
	
	{
		double price, bill;
		int number;

		cout << "Enter the number of items purchased: ";
		cin >> number;
		cout << "Enter the price per item$";
		cin >> price;

		bill = totalCost(number, price);

		cout.setf(ios::fixed);
		cout.setf(ios::showpoint);
		cout.precision(2);
		cout << number << " items at "
			<< "$" << price << " each.\n"
			<< "Final bill, including tax, is $" << bill
			<< endl;
		return 0; 
	}

	double totalCost(int numberParameter, double priceParameter)
	{
		const double TAXRATE = 0.05; //5$ sales tax
		double subtotal;

		subtotal = priceParameter * numberParameter;
		return (subtotal + subtotal*TAXRATE);
	}
	
	
	system("pause");
	return 0;
}
Last edited on
Your totalCost function is WITHIN main!

Its a separate function, move it outside of main and it'll work fine.
Thanks! Can't believe I didn't see that. Does it matter where a function is defined? Could I have defined it before main?

edit: I just tested it. It works. Thanks again!
Last edited on
Topic archived. No new replies allowed.