Hello,
this is my first post, so i'm sure i'll fumble it a little bit.

I'm writing a program that has a switch, a nested if, and an output choice of console or new file on a:.
I feel like all my switch and nest is good, but i'm missing something, like a preprocessor. at least i hope I'm that close

here's a list of errors:

LINE 49 call to undefined function 'SWITCH' in function main()
LINE 49statement missing ; in function main()
LINE 96possible use of tot_chrg' before definition in function main()
LINE 101undefined symbol 'choice in function main()
LINES 113 115 117 119 statement missing ; in function main // this appears four times
LINE 127[three of my different variable names: water_chrg school_fee elec_chrg] are used but never defined in function main()
LINE 127[two of my variable names: bal_due SAN_CHARGE] is assigned a value that is never used in function main()


thanks
jamie

Start by remembering that C++ is case sensitive. Then make sure that every variable you use is defined before it's used.

I guess i'm not exactly sure what 'defined' means; doesn't the result of my switch and nested if statements define them?

>I guess i'm not exactly sure what 'defined' means
Your variable tells the compiler, "Here I am! I exist. Set aside storage for me." And you do it like so:

int main()
{
  int variable; // variable is now defined

  // ...
}

>doesn't the result of my switch and nested if statements define them?
Not in C++.

I guess I'm in over my head; are we talking about this section?

const double SAN_CHARGE = 12.50,
TAX_RATE = 0.07;

char account [6], // No dashes
date [20]; // Month Day, Year

ofstream outfile;

int children;

long int electric,
water;

double bal_due,
elec_chrg,
school_fee,
tax,
tot_chrg,
water_chrg;

commented: Use code tags. +0

>I guess I'm in over my head
One problem at a time. Change your keywords (switch, if, else, and so on) to lower case first, then you should compile with only warnings and we'll work from there.

it still won't compile.. i think i'm up the proverbial creek!

should it be:

int main ()

?

>it still won't compile..
Then post the code (don't attach it).

thank you so much!

//*****************************PRE PROCESSORS***********************************
#include <iomanip.h>
#include <fstream.h>
//**********************************MAIN****************************************
int main ()
{
	  const double  SAN_CHARGE = 12.50,
						 TAX_RATE   = 0.07;

	  char      account [6],  //  No dashes
					date [20];    //  Month Day, Year

	  ofstream outfile;

	  int       children;

	  long int  electric,
					water;

	  double    bal_due,
					elec_chrg,
					school_fee,
					tax,
					tot_chrg,
					water_chrg;

	  cout  <<  "Enter today's date:" << endl;
	  cin.getline (date, sizeof (date));
	  cout  <<  "Enter the account number:"  <<  endl;
	  cin.getline (account, sizeof (account));
	  cout  <<  "Enter the number of children in the household:"  <<  endl;
	  cin   >>  children;
	  cout  <<  "Enter the number of gallons of water used in the household:"  << endl;
	  cin   >>  water;
	  cout  <<  "Enter the amount of electricity used in the household (in kwh):"  <<  endl;
	  cin   >>  electric;

	  switch (children)
      {
				case 0:
						school_fee = 100.00;
						break;
				case 1:
				case 2:
						school_fee = 200.00;
						break;
				case 3:
				case 4:
				case 5:
						school_fee = 250.00;
				default:
						school_fee = 300.00;
						break;
	  }


	  if (water < 1500){
			water_chrg = .0125;}
	  else if (water == 1500){
			water_chrg = 21.20;}
	  else if (water <= 1999){
			water_chrg = 21.2142;}
	  else if (water == 2000){
			water_chrg = 25.85;}
	  else{
			water_chrg = 25.8665;}


	  if (electric < 400){
			elec_chrg = .053;}
	  else if (electric == 400){
			elec_chrg = 21.20;}
	  else if (electric <= 699){
			elec_chrg = 21.261;}
	  else if (electric == 700){
			elec_chrg = 39.50;}
	  else if (electric <= 999){
			elec_chrg = 39.573;}
	  else if (electric == 1000){
			elec_chrg = 61.40;}
	  else{
			elec_chrg = 61.488;}


	  tot_chrg = school_fee + water_chrg + elec_chrg + SAN_CHRG;
	  tax      = TAX_RATE * tot_chrg;
	  bal_due  = tax + tot_chrg;


	  cout  <<  "Direct output to the console (1) or to a disk file (2):  ";
	  cin   >>  choice;
	  if    (choice == 1)
			  outfile.open ( "con" );
	  else
			  outfile.open ( "a:result.dta" );


	  outfile  <<  setiosflags (ios::showpoint | ios::fixed)  <<  setprecision (0);
	  outfile  <<  setw(47)  <<  "Town of Hopewell"  <<  endl;
	  outfile  <<  setw(47)  <<  "----------------"  <<  endl  <<  endl;
	  outfile  <<  "Date:                       "  <<  endl  <<  endl;
	  outfile  <<  "Account:                    "  <<  endl  <<  endl;
	  outfile  <<  setw(20)  <<  "Children"  <<  setw(13)  "School Fee"  <<  setw(18)
				  <<  "Water (gallons)"  <<  setw(15)  <<  "Water Charge"  <<  endl;
	  outfile  <<  setw(20)  <<  children  <<  setw(13)  school_fee  <<  setw(18)
				  <<  water  <<  setw(15)  <<  water_chrg  <<  endl  <<  endl;
	  outfile  <<  setw(26)  <<  "Electric (kwh)"  <<  setw(19)  "Electric Charge"  <<  setw(21)
				  <<  "Sanitation Charge"  <<  endl;
	  outfile  <<  setw(26)  <<  electric  <<  setw(19)  elec_chrg  <<  setw(21)
				  <<  SAN_CHRG  <<  endl  <<  endl;
	  outfile  <<  "Total Charge:  "  <<  endl  <<  endl;
	  outfile  <<  "Tax:           "  <<  endl  <<  endl;
	  outfile  <<  "Balance Due:   "  <<  endl  <<  endl;


	  outfile.close ( );
}

Okay, now include <iostream.h> and declare your variables. Notice that what we're doing here is incremental fixes. There are so many problems that you can only work with one at a time, so you walk down the list of errors from the top, recompiling as you fix them because sometimes one fix will remove several error messages.

More correct C++ usage is to omit the .h from the standard includes. Using the #include <x.h> instead of #include <x> turns on C compatibility mode for the module.

Depending on your compiler you'll get a warning or not about it.

>More correct C++ usage is to omit the .h from the standard includes.
Let's get the code working first, then get into style and form issues, k?

I added the preprosessor; it didn't seem to help.

I thought I had already declared my variables; what did I do wrong?

I added the preprosessor; it didn't seem to help.

I thought I had already declared my variables; what did I do wrong?

>what did I do wrong?
Without your current code, I'll never know.

All I changed was the preprocessor; i added <iostream.h> like you said; i thought that the declaration section was the next section and I'd already declared my variables. my code is posted at post: 11-10-2004, 05:18 PM

//*****************************PRE PROCESSORS***********************************
#include <iomanip.h>
#include <fstream.h>
#include <iostream.h>
//**********************************MAIN*********************************

>what did I do wrong?
Without your current code, I'll never know.

all i did was add the preprocessor you suggested. there was no change

i thought i had already declared all my variables (see my previous post)

i'm in so much trouble if i don't finish this by monday and i'm so lost...

//*****************************PRE PROCESSORS***********************************
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
//**********************************MAIN****************************************
int main ()
{
  const double SAN_CHARGE = 12.50,
    TAX_RATE = 0.07;

  char account [6],  //  No dashes
    date [20];    //  Month Day, Year

  ofstream outfile;

  int children,
    choice;

  long int electric,
    water;

  double bal_due,
    elec_chrg,
    school_fee,
    tax,
    tot_chrg,
    water_chrg;

  cout  <<  "Enter today's date:" << endl;
  cin.getline (date, sizeof (date));
  cout  <<  "Enter the account number:"  <<  endl;
  cin.getline (account, sizeof (account));
  cout  <<  "Enter the number of children in the household:"  <<  endl;
  cin   >>  children;
  cout  <<  "Enter the number of gallons of water used in the household:"  << endl;
  cin   >>  water;
  cout  <<  "Enter the amount of electricity used in the household (in kwh):"  <<  endl;
  cin   >>  electric;

  switch (children)
  {
  case 0:
    school_fee = 100.00;
    break;
  case 1:
  case 2:
    school_fee = 200.00;
    break;
  case 3:
  case 4:
  case 5:
    school_fee = 250.00;
  default:
    school_fee = 300.00;
    break;
  }

  if (water < 1500){
    water_chrg = .0125;}
  else if (water == 1500){
    water_chrg = 21.20;}
  else if (water <= 1999){
    water_chrg = 21.2142;}
  else if (water == 2000){
    water_chrg = 25.85;}
  else{
    water_chrg = 25.8665;}

  if (electric < 400){
    elec_chrg = .053;}
  else if (electric == 400){
    elec_chrg = 21.20;}
  else if (electric <= 699){
    elec_chrg = 21.261;}
  else if (electric == 700){
    elec_chrg = 39.50;}
  else if (electric <= 999){
    elec_chrg = 39.573;}
  else if (electric == 1000){
    elec_chrg = 61.40;}
  else{
    elec_chrg = 61.488;}

  tot_chrg = school_fee + water_chrg + elec_chrg + SAN_CHARGE;
  tax      = TAX_RATE * tot_chrg;
  bal_due  = tax + tot_chrg;

  cout  <<  "Direct output to the console (1) or to a disk file (2):  ";
  cin   >>  choice;
  if    (choice == 1)
    outfile.open ( "con" );
  else
    outfile.open ( "a:result.dta" );

  outfile<< setiosflags (ios::showpoint | ios::fixed) << setprecision (0);
  outfile<< setw(47)  <<  "Town of Hopewell"<<endl;
  outfile<< setw(47)  <<  "----------------"<<endl<<endl;
  outfile<<"Date:                       "<<endl<<endl;
  outfile<<"Account:                    "<<endl<<endl;
  outfile<< setw(20) <<"Children"<< setw(13) <<"School Fee"<< setw(18)
    <<"Water (gallons)"<< setw(15) <<"Water Charge"<<endl;
  outfile<< setw(20) << children << setw(13) << school_fee << setw(18)
    << water << setw(15) << water_chrg <<endl<<endl;
  outfile<< setw(26) <<"Electric (kwh)"<< setw(19) <<"Electric Charge"
    << setw(21) <<"Sanitation Charge"<<endl;
  outfile<< setw(26) << electric << setw(19) << elec_chrg << setw(21)
    << SAN_CHARGE <<endl<<endl;
  outfile<<"Total Charge:  "<<endl<<endl;
  outfile<<"Tax:           "<<endl<<endl;
  outfile<<"Balance Due:   "<<endl<<endl;

  outfile.close ( );
}

Now go away.

my current code is below, but first, here are my error messages (some of them seem really strange). if I don't get this done by monday, life as I know it will come to a crashing halt.

11 C:\Program Files\Dev-Cpp\include\c++\3.3.1\backward\iomanip.h:31,               
from C:\TEMP\hopewll.cpp In file included from C:/Program Files/Dev-Cpp/include/c++/3.3.1/backward/iomanip.h:31,               
from C:/TEMP/hopewll.cpp 
11 C:\TEMP\hopewll.cpp                  from C:/TEMP/hopewll.cpp 
2 C:\Program Files\Dev-Cpp\include\c++\3.3.1\backward\backward_warning.h:32 #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated. 
 C:\TEMP\hopewll.cpp In function `int main()': 
49 C:\TEMP\hopewll.cpp `SWITCH' undeclared (first use this function) 
(Each undeclared identifier is reported only  once for each function it appears in.) 
50 C:\TEMP\hopewll.cpp syntax error before `{' token 
54 C:\TEMP\hopewll.cpp case label `1' not within a switch statement 
55 C:\TEMP\hopewll.cpp case label `2' not within a switch statement 
58 C:\TEMP\hopewll.cpp case label `3' not within a switch statement 
59 C:\TEMP\hopewll.cpp case label `4' not within a switch statement 
60 C:\TEMP\hopewll.cpp case label `5' not within a switch statement 
62 C:\TEMP\hopewll.cpp `default' label not within a switch statement 
53 C:\TEMP\hopewll.cpp break statement not within loop or switch 
57 C:\TEMP\hopewll.cpp break statement not within loop or switch 
64 C:\TEMP\hopewll.cpp break statement not within loop or switch 
/TEMP/hopewll.cpp C:\TEMP\C At global scope: 
68 C:\TEMP\hopewll.cpp `water' was not declared in this scope 
68 C:\TEMP\hopewll.cpp ISO C++ forbids declaration of `IF' with no type 

WELL, THERE ARE A LOT MORE, SO I'LL LET IT GO FROM HERE.

//*****************************PRE PROCESSORS***********************************
#include <iomanip.h>
#include <fstream.h>
#include <iostream.h>
//**********************************MAIN****************************************
int main ()
{

      const double  SAN_CHARGE = 12.50,
                         TAX_RATE   = 0.07;

      char      account [6],  //  No dashes
                    date [20];    //  Month Day, Year

      ofstream outfile;

      int       children;

      long int  electric,
                    water;

      double    bal_due,
                    elec_chrg,
                    school_fee,
                    tax,
                    tot_chrg,
                    water_chrg;

      cout  <<  "Enter today's date:" << endl;
      cin.getline (date, sizeof (date));
      cout  <<  "Enter the account number:"  <<  endl;
      cin.getline (account, sizeof (account));
      cout  <<  "Enter the number of children in the household:"  <<  endl;
      cin   >>  children;
      cout  <<  "Enter the number of gallons of water used in the household:"  << endl;
      cin   >>  water;
      cout  <<  "Enter the amount of electricity used in the household (in kwh):"  <<  endl;
      cin   >>  electric;

      SWITCH (children)
      {
                case 0:
                        school_fee = 100.00;
                        break;
                case 1:
                case 2:
                        school_fee = 200.00;
                        break;
                case 3:
                case 4:
                case 5:
                        school_fee = 250.00;
                default:
                        school_fee = 300.00;
                        break;
      }


      IF (water < 1500){
            water_chrg = .0125;}
      ELSE IF (water == 1500){
            water_chrg = 21.20;}
      ELSE IF (water <= 1999){
            water_chrg = 21.2142;}
      ELSE IF (water == 2000){
            water_chrg = 25.85;}
      ELSE{
            water_chrg = 25.8665;}


      IF (electric < 400){
            elec_chrg = .053;}
      ELSE IF (electric == 400){
            elec_chrg = 21.20;}
      ELSE IF (electric <= 699){
            elec_chrg = 21.261;}
      ELSE IF (electric == 700){
            elec_chrg = 39.50;}
      ELSE IF (electric <= 999){
            elec_chrg = 39.573;}
      ELSE IF (electric == 1000){
            elec_chrg = 61.40;}
      ELSE{
            elec_chrg = 61.488;}


      tot_chrg = school_fee + water_chrg + elec_chrg + SAN_CHRG;
      tax      = TAX_RATE * tot_chrg;
      bal_due  = tax + tot_chrg;


      cout  <<  "Direct output to the console (1) or to a disk file (2):  ";
      cin   >>  choice;
      if    (choice == 1)
              outfile.open ( "con" );
      else
              outfile.open ( "a:result.dta" );


      outfile  <<  setiosflags (ios::showpoint | ios::fixed)  <<  setprecision (0);
      outfile  <<  setw(47)  <<  "Town of Hopewell"  <<  endl;
      outfile  <<  setw(47)  <<  "----------------"  <<  endl  <<  endl;
      outfile  <<  "Date:                       "  <<  endl  <<  endl;
      outfile  <<  "Account:                    "  <<  endl  <<  endl;
      outfile  <<  setw(20)  <<  "Children"  <<  setw(13)  "School Fee"  <<  setw(18)
                  <<  "Water (gallons)"  <<  setw(15)  <<  "Water Charge"  <<  endl;
      outfile  <<  setw(20)  <<  children  <<  setw(13)  school_fee  <<  setw(18)
                  <<  water  <<  setw(15)  <<  water_chrg  <<  endl  <<  endl;
      outfile  <<  setw(26)  <<  "Electric (kwh)"  <<  setw(19)  "Electric Charge"  <<  setw(21)
                  <<  "Sanitation Charge"  <<  endl;
      outfile  <<  setw(26)  <<  electric  <<  setw(19)  elec_chrg  <<  setw(21)
                  <<  SAN_CHRG  <<  endl  <<  endl;
      outfile  <<  "Total Charge:  "  <<  endl  <<  endl;
      outfile  <<  "Tax:           "  <<  endl  <<  endl;
      outfile  <<  "Balance Due:   "  <<  endl  <<  endl;


      outfile.close ( );
}

i changed all the keywords to lower case

OK I have a lot less errors now. The errors are first, then the code:

11 C:\Program Files\Dev-Cpp\include\c++\3.3.1\backward\iomanip.h:31,               from C:\TEMP\hopewll.cpp In file included from C:/Program Files/Dev-Cpp/include/c++/3.3.1/backward/iomanip.h:31,               from C:/TEMP/hopewll.cpp 

11 C:\TEMP\hopewll.cpp                  from C:/TEMP/hopewll.cpp 

2 C:\Program Files\Dev-Cpp\include\c++\3.3.1\backward\backward_warning.h:32 #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated. 

 C:\TEMP\hopewll.cpp In function `int main()': 

95 C:\TEMP\hopewll.cpp `SAN_CHRG' undeclared (first use this function) 

  (Each undeclared identifier is reported only  once for each function it appears in.) 

101 C:\TEMP\hopewll.cpp `choice' undeclared (first use this function) 

113 C:\TEMP\hopewll.cpp syntax error before string constant 

115 C:\TEMP\hopewll.cpp syntax error before `<<' token 

117 C:\TEMP\hopewll.cpp syntax error before string constant 

119 C:\TEMP\hopewll.cpp syntax error before `<<' token 







//*****************************PRE PROCESSORS***********************************
#include <iomanip.h>
#include <fstream.h>
#include <iostream.h>
//**********************************MAIN****************************************
int main ()
{

      const double  SAN_CHARGE = 12.50,
                         TAX_RATE   = 0.07;

      char      account [6],  //  No dashes
                    date [20];    //  Month Day, Year

      ofstream outfile;

      int       children;

      long int  electric,
                    water;

      double    bal_due,
                    elec_chrg,
                    school_fee,
                    tax,
                    tot_chrg,
                    water_chrg;

      cout  <<  "Enter today's date:" << endl;
      cin.getline (date, sizeof (date));
      cout  <<  "Enter the account number:"  <<  endl;
      cin.getline (account, sizeof (account));
      cout  <<  "Enter the number of children in the household:"  <<  endl;
      cin   >>  children;
      cout  <<  "Enter the number of gallons of water used in the household:"  << endl;
      cin   >>  water;
      cout  <<  "Enter the amount of electricity used in the household (in kwh):"  <<  endl;
      cin   >>  electric;

      switch (children){
                case 0:
                        school_fee = 100.00;
                        break;
                case 1:
                case 2:
                        school_fee = 200.00;
                        break;
                case 3:
                case 4:
                case 5:
                        school_fee = 250.00;
                default:
                        school_fee = 300.00;
                        break;
      }


      if (water < 1500){
            water_chrg = .0125;}
      else if (water == 1500){
            water_chrg = 21.20;}
      else if (water <= 1999){
            water_chrg = 21.2142;}
      else if (water == 2000){
            water_chrg = 25.85;}
      else{
            water_chrg = 25.8665;}


      if (electric < 400){
            elec_chrg = .053;}
      else if (electric == 400){
            elec_chrg = 21.20;}
      else if (electric <= 699){
            elec_chrg = 21.261;}
      else if (electric == 700){
            elec_chrg = 39.50;}
      else if (electric <= 999){
            elec_chrg = 39.573;}
      else if (electric == 1000){
            elec_chrg = 61.40;}
      else{
            elec_chrg = 61.488;}


      tot_chrg = school_fee + water_chrg + elec_chrg + SAN_CHRG;
      tax      = TAX_RATE * tot_chrg;
      bal_due  = tax + tot_chrg;


      cout  <<  "Direct output to the console (1) or to a disk file (2):  ";
      cin   >>  choice;
      if    (choice == 1)
              outfile.open ( "con" );
      else
              outfile.open ( "a:result.dta" );


      outfile  <<  setiosflags (ios::showpoint | ios::fixed)  <<  setprecision (0);
      outfile  <<  setw(47)  <<  "Town of Hopewell"  <<  endl;
      outfile  <<  setw(47)  <<  "----------------"  <<  endl  <<  endl;
      outfile  <<  "Date:                       "  <<  endl  <<  endl;
      outfile  <<  "Account:                    "  <<  endl  <<  endl;
      outfile  <<  setw(20)  <<  "Children"  <<  setw(13)  "School Fee"  <<  setw(18)
                  <<  "Water (gallons)"  <<  setw(15)  <<  "Water Charge"  <<  endl;
      outfile  <<  setw(20)  <<  children  <<  setw(13)  school_fee  <<  setw(18)
                  <<  water  <<  setw(15)  <<  water_chrg  <<  endl  <<  endl;
      outfile  <<  setw(26)  <<  "Electric (kwh)"  <<  setw(19)  "Electric Charge"  <<  setw(21)
                  <<  "Sanitation Charge"  <<  endl;
      outfile  <<  setw(26)  <<  electric  <<  setw(19)  elec_chrg  <<  setw(21)
                  <<  SAN_CHRG  <<  endl  <<  endl;
      outfile  <<  "Total Charge:  "  <<  endl  <<  endl;
      outfile  <<  "Tax:           "  <<  endl  <<  endl;
      outfile  <<  "Balance Due:   "  <<  endl  <<  endl;


      outfile.close ( );
}

I got rid of the error below; I had it spelled differently.

95 C:\TEMP\hopewll.cppSAN_CHRG' undeclared (first use this function)`

here's where I'm at now

//*****************************PRE PROCESSORS***********************************
#include <iomanip.h>
#include <fstream.h>
#include <iostream.h>
//**********************************MAIN****************************************
int main ()
{

      const double  SAN_CHRG = 12.50,
                         TAX_RATE   = 0.07;

      char      account [6],  //  No dashes
                    date [20];    //  Month Day, Year

      ofstream outfile;

      int       children;

      long int  electric,
                    water;

      double    bal_due,
                    elec_chrg,
                    school_fee,
                    tax,
                    tot_chrg,
                    water_chrg;

      cout  <<  "Enter today's date:" << endl;
      cin.getline (date, sizeof (date));
      cout  <<  "Enter the account number:"  <<  endl;
      cin.getline (account, sizeof (account));
      cout  <<  "Enter the number of children in the household:"  <<  endl;
      cin   >>  children;
      cout  <<  "Enter the number of gallons of water used in the household:"  << endl;
      cin   >>  water;
      cout  <<  "Enter the amount of electricity used in the household (in kwh):"  <<  endl;
      cin   >>  electric;

      switch (children){
                case 0:
                        school_fee = 100.00;
                        break;
                case 1:
                case 2:
                        school_fee = 200.00;
                        break;
                case 3:
                case 4:
                case 5:
                        school_fee = 250.00;
                default:
                        school_fee = 300.00;
                        break;
      }


      if (water < 1500){
            water_chrg = .0125;}
      else if (water == 1500){
            water_chrg = 21.20;}
      else if (water <= 1999){
            water_chrg = 21.2142;}
      else if (water == 2000){
            water_chrg = 25.85;}
      else{
            water_chrg = 25.8665;}


      if (electric < 400){
            elec_chrg = .053;}
      else if (electric == 400){
            elec_chrg = 21.20;}
      else if (electric <= 699){
            elec_chrg = 21.261;}
      else if (electric == 700){
            elec_chrg = 39.50;}
      else if (electric <= 999){
            elec_chrg = 39.573;}
      else if (electric == 1000){
            elec_chrg = 61.40;}
      else{
            elec_chrg = 61.488;}


      tot_chrg = school_fee + water_chrg + elec_chrg + SAN_CHRG;
      tax      = TAX_RATE * tot_chrg;
      bal_due  = tax + tot_chrg;


      cout  <<  "Direct output to the console (1) or to a disk file (2):  ";
      cin   >>  choice;
      if    (choice == 1)
              outfile.open ( "con" );
      else
              outfile.open ( "a:result.dta" );


      outfile  <<  setiosflags (ios::showpoint | ios::fixed)  <<  setprecision (0);
      outfile  <<  setw(47)  <<  "Town of Hopewell"  <<  endl;
      outfile  <<  setw(47)  <<  "----------------"  <<  endl  <<  endl;
      outfile  <<  "Date:                       "  <<  endl  <<  endl;
      outfile  <<  "Account:                    "  <<  endl  <<  endl;
      outfile  <<  setw(20)  <<  "Children"  <<  setw(13)  "School Fee"  <<  setw(18)
                  <<  "Water (gallons)"  <<  setw(15)  <<  "Water Charge"  <<  endl;
      outfile  <<  setw(20)  <<  children  <<  setw(13)  school_fee  <<  setw(18)
                  <<  water  <<  setw(15)  <<  water_chrg  <<  endl  <<  endl;
      outfile  <<  setw(26)  <<  "Electric (kwh)"  <<  setw(19)  "Electric Charge"  <<  setw(21)
                  <<  "Sanitation Charge"  <<  endl;
      outfile  <<  setw(26)  <<  electric  <<  setw(19)  elec_chrg  <<  setw(21)
                  <<  SAN_CHRG  <<  endl  <<  endl;
      outfile  <<  "Total Charge:  "  <<  endl  <<  endl;
      outfile  <<  "Tax:           "  <<  endl  <<  endl;
      outfile  <<  "Balance Due:   "  <<  endl  <<  endl;


      outfile.close ( );
}

>here's where I'm at now
You don't pay much attention, do you? Look up four posts in this thread.

what did I do wrong?
Without your current code, I'll never know.

now it won't compile again; it says the source code is incomplete, but I can't see how (there's a surprise). actually, i don't even know what they mean.

//*****************************PRE PROCESSORS***********************************
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
//**********************************MAIN****************************************
int main ()
{
  const double SAN_CHARGE = 12.50,
               TAX_RATE = 0.07;

  char account [6],  //  No dashes
       date [20];    //  Month Day, Year

  ofstream outfile;

  int children,
      choice;

  long int electric,
           water;

  double bal_due,
         elec_chrg,
         school_fee,
         tax,
         tot_chrg,
         water_chrg;

  cout  <<  "Enter today's date:" << endl;
  cin.getline (date, sizeof (date));
  cout  <<  "Enter the account number:"  <<  endl;
  cin.getline (account, sizeof (account));
  cout  <<  "Enter the number of children in the household:"  <<  endl;
  cin   >>  children;
  cout  <<  "Enter the number of gallons of water used in the household:"  << endl;
  cin   >>  water;
  cout  <<  "Enter the amount of electricity used in the household (in kwh):"  <<  endl;
  cin   >>  electric;

  switch (children)
  {
  case 0:
    school_fee = 100.00;
    break;
  case 1:
  case 2:
    school_fee = 200.00;
    break;
  case 3:
  case 4:
  case 5:
    school_fee = 250.00;
  default:
    school_fee = 300.00;
    break;
  }

  if (water < 1500){
    water_chrg = .0125;}
  else if (water == 1500){
    water_chrg = 21.20;}
  else if (water <= 1999){
    water_chrg = 21.2142;}
  else if (water == 2000){
    water_chrg = 25.85;}
  else{
    water_chrg = 25.8665;}

  if (electric < 400){
    elec_chrg = .053;}
  else if (electric == 400){
    elec_chrg = 21.20;}
  else if (electric <= 699){
    elec_chrg = 21.261;}
  else if (electric == 700){
    elec_chrg = 39.50;}
  else if (electric <= 999){
    elec_chrg = 39.573;}
  else if (electric == 1000){
    elec_chrg = 61.40;}
  else{
    elec_chrg = 61.488;}

  tot_chrg = school_fee + water_chrg + elec_chrg + SAN_CHARGE;
  tax      = TAX_RATE * tot_chrg;
  bal_due  = tax + tot_chrg;

  cout  <<  "Direct output to the console (1) or to a disk file (2):  ";
  cin   >>  choice;
  if    (choice == 1)
    outfile.open ( "con" );
  else
    outfile.open ( "a:result.dta" );

  outfile  <<  setiosflags (ios::showpoint | ios::fixed) << setprecision (0);
  outfile  <<  setw(47)  <<  "Town of Hopewell"  <<endl;
  outfile  <<  setw(47)  <<  "----------------"  <<endl  <<endl;
  outfile  <<  "Date:                       "  date  <<endl  <<endl;
  outfile  <<  "Account:                    "  account  <<endl  <<endl;
  outfile  <<  setw(20)  <<  "Children"  <<  setw(13) <<  "School Fee"  << setw(18)
           <<  "Water (gallons)"  << setw(15) <<  "Water Charge"  <<  endl;
  outfile  <<  setw(20)  <<  children  <<  setw(13)  <<  school_fee  <<  setw(18)
           <<  water  <<  setw(15)  <<  water_chrg  <<  endl  <<  endl;
  outfile  <<  setw(26)  <<  "Electric (kwh)"  <<  setw(19)  <<  "Electric Charge"
           <<  setw(21)  <<  "Sanitation Charge"  <<endl;
  outfile  <<  setw(26)  <<  electric  <<  setw(19)  <<  elec_chrg  <<  setw(21)
           <<  SAN_CHARGE  <<  endl  <<  endl;
  outfile  <<  "Total Charge:  "  tot_chrg  <<  endl  <<  endl;
  outfile  <<  "Tax:           "  tax  <<  endl  <<  endl;
  outfile  <<  "Balance Due:   "  bal_due  <<  endl  <<  endl;

  outfile.close ( );
}

>now it won't compile again
That's because you didn't read the code to see what I changed and made the same mistake again.

>outfile << "Date: " date <<endl <<endl;
outfile << "Date: "<< date <<endl <<endl;

Repeat that change on every line your compiler bitches about until it compiles.

>now it won't compile again
That's because you didn't read the code to see what I changed and made the same mistake again.

>outfile << "Date: " date <<endl <<endl;
outfile << "Date: "<< date <<endl <<endl;

Repeat that change on every line your compiler bitches about until it compiles.

yeah i found it right after I posted it; I made the corrections and I think everything is OK now; thanks! (atleast until I break it again, but i think it's OK.

>now it won't compile again
That's because you didn't read the code to see what I changed and made the same mistake again.

>outfile << "Date: " date <<endl <<endl;
outfile << "Date: "<< date <<endl <<endl;

Repeat that change on every line your compiler bitches about until it compiles.

the only strange thing is in my results; theres nothing after the decimal places, not even 00.
the result comes out like 400.
insead of 400.00

>theres nothing after the decimal places
That's because you asked for that behavior:

outfile << setiosflags (ios::showpoint | ios::fixed) << [B]setprecision (0)[/B];

>theres nothing after the decimal places
That's because you asked for that behavior:

outfile << setiosflags (ios::showpoint | ios::fixed) << [B]setprecision (0)[/B];

you mean I need to change the setpreciision?

>theres nothing after the decimal places
That's because you asked for that behavior:

outfile << setiosflags (ios::showpoint | ios::fixed) << [B]setprecision (0)[/B];

I get it! the precision number refers to the number of decimal places! You're the coolest! :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.