### Natural Gas Billing Rate (undeclared Identifiers)

Hi I have to write a program that takes 2 inputs to indicate the amount of gas used and then calculate how much that amount of gas would cost according to the chart at the top of my program. The first input would be a 5 digit number for the amount of gas used previous month and the second input would also be a 5 digit number for the amount used for the current month. I am getting undeclared identifiers for my first cout and cin. Also if you spot any other errors please let me know. Thanks.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142`` ``````#include #include /* RULES: First 10 cubic meters \$15.21 minimum cost Next 30 cubic meters 35.85 cents per cubic meter Next 85 cubic meters 33.53 cents per cubic meter Next 165 cubic meters 30.26 cents per cubic meter Above 290 cubic meters 27.95 cents per cubic meter */ int main() { int first_month; int second_month; int number; double total = 15.21; double price; cout<<"Enter your meter number from the previous month: "; cin>>first_month; cout<<"Enter your meter munber from the current month: "; cin>>second_month; number=second_month-first_month; if( number <= 10 ) { cout<<"Total price: \$%.", total; return 0; } else if( number <= 40 ) price = 0.3585; else if( number <= 125 ) price = 0.3353; else if( number <= 290 ) price = 0.3026; else if (number > 290) price = 0.2795; total = price * number; cout<<("The total price is: \$%.", total ); return 0; } ``````
The cin and cout streams are defined in the 'std' namespace. So if you use any of these streams, you have to either declare "using namespace std;" before your main loop starts (without the quotes) or use code like the following.
 ``12`` ``````std::cout << "Enter your meter number.."; std::cin >> first_month;``````

Some useful/interesting material on namespaces. :)

http://www.cplusplus.com/doc/tutorial/namespaces/
Last edited on
haha I knew I was missing something thanks.
You're welcome. If you have any other questions, don't hesitate to ask. We've got a helpful bunch of programmers on this forum. :)
Topic archived. No new replies allowed.