program w/ switch AND nested if. six error messages

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2004
Posts: 21
Reputation: jamievmi2 is an unknown quantity at this point 
Solved Threads: 0
jamievmi2 jamievmi2 is offline Offline
Newbie Poster

program w/ switch AND nested if. six error messages

 
0
  #1
Nov 10th, 2004
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
Attached Files
File Type: cpp hopewll.cpp (3.7 KB, 5 views)
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 715
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: program w/ switch AND nested if. six error messages

 
0
  #2
Nov 10th, 2004
Start by remembering that C++ is case sensitive. Then make sure that every variable you use is defined before it's used.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 21
Reputation: jamievmi2 is an unknown quantity at this point 
Solved Threads: 0
jamievmi2 jamievmi2 is offline Offline
Newbie Poster

Re: program w/ switch AND nested if. six error messages

 
0
  #3
Nov 10th, 2004
I guess i'm not exactly sure what 'defined' means; doesn't the result of my switch and nested if statements define them?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 715
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: program w/ switch AND nested if. six error messages

 
0
  #4
Nov 10th, 2004
>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:
  1. int main()
  2. {
  3. int variable; // variable is now defined
  4.  
  5. // ...
  6. }
>doesn't the result of my switch and nested if statements define them?
Not in C++.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 21
Reputation: jamievmi2 is an unknown quantity at this point 
Solved Threads: 0
jamievmi2 jamievmi2 is offline Offline
Newbie Poster

Re: program w/ switch AND nested if. six error messages

 
-1
  #5
Nov 10th, 2004
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;
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 715
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: program w/ switch AND nested if. six error messages

 
0
  #6
Nov 10th, 2004
>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.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 21
Reputation: jamievmi2 is an unknown quantity at this point 
Solved Threads: 0
jamievmi2 jamievmi2 is offline Offline
Newbie Poster

Re: program w/ switch AND nested if. six error messages

 
0
  #7
Nov 10th, 2004
it still won't compile.. i think i'm up the proverbial creek!

should it be:

int main ()

?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 715
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: program w/ switch AND nested if. six error messages

 
0
  #8
Nov 10th, 2004
>it still won't compile..
Then post the code (don't attach it).
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 21
Reputation: jamievmi2 is an unknown quantity at this point 
Solved Threads: 0
jamievmi2 jamievmi2 is offline Offline
Newbie Poster

Re: program w/ switch AND nested if. six error messages

 
0
  #9
Nov 10th, 2004
thank you so much!


  1.  
  2. //*****************************PRE PROCESSORS***********************************
  3. #include <iomanip.h>
  4. #include <fstream.h>
  5. //**********************************MAIN****************************************
  6. int main ()
  7. {
  8. const double SAN_CHARGE = 12.50,
  9. TAX_RATE = 0.07;
  10.  
  11. char account [6], // No dashes
  12. date [20]; // Month Day, Year
  13.  
  14. ofstream outfile;
  15.  
  16. int children;
  17.  
  18. long int electric,
  19. water;
  20.  
  21. double bal_due,
  22. elec_chrg,
  23. school_fee,
  24. tax,
  25. tot_chrg,
  26. water_chrg;
  27.  
  28. cout << "Enter today's date:" << endl;
  29. cin.getline (date, sizeof (date));
  30. cout << "Enter the account number:" << endl;
  31. cin.getline (account, sizeof (account));
  32. cout << "Enter the number of children in the household:" << endl;
  33. cin >> children;
  34. cout << "Enter the number of gallons of water used in the household:" << endl;
  35. cin >> water;
  36. cout << "Enter the amount of electricity used in the household (in kwh):" << endl;
  37. cin >> electric;
  38.  
  39. switch (children)
  40. {
  41. case 0:
  42. school_fee = 100.00;
  43. break;
  44. case 1:
  45. case 2:
  46. school_fee = 200.00;
  47. break;
  48. case 3:
  49. case 4:
  50. case 5:
  51. school_fee = 250.00;
  52. default:
  53. school_fee = 300.00;
  54. break;
  55. }
  56.  
  57.  
  58. if (water < 1500){
  59. water_chrg = .0125;}
  60. else if (water == 1500){
  61. water_chrg = 21.20;}
  62. else if (water <= 1999){
  63. water_chrg = 21.2142;}
  64. else if (water == 2000){
  65. water_chrg = 25.85;}
  66. else{
  67. water_chrg = 25.8665;}
  68.  
  69.  
  70. if (electric < 400){
  71. elec_chrg = .053;}
  72. else if (electric == 400){
  73. elec_chrg = 21.20;}
  74. else if (electric <= 699){
  75. elec_chrg = 21.261;}
  76. else if (electric == 700){
  77. elec_chrg = 39.50;}
  78. else if (electric <= 999){
  79. elec_chrg = 39.573;}
  80. else if (electric == 1000){
  81. elec_chrg = 61.40;}
  82. else{
  83. elec_chrg = 61.488;}
  84.  
  85.  
  86. tot_chrg = school_fee + water_chrg + elec_chrg + SAN_CHRG;
  87. tax = TAX_RATE * tot_chrg;
  88. bal_due = tax + tot_chrg;
  89.  
  90.  
  91. cout << "Direct output to the console (1) or to a disk file (2): ";
  92. cin >> choice;
  93. if (choice == 1)
  94. outfile.open ( "con" );
  95. else
  96. outfile.open ( "a:result.dta" );
  97.  
  98.  
  99. outfile << setiosflags (ios::showpoint | ios::fixed) << setprecision (0);
  100. outfile << setw(47) << "Town of Hopewell" << endl;
  101. outfile << setw(47) << "----------------" << endl << endl;
  102. outfile << "Date: " << endl << endl;
  103. outfile << "Account: " << endl << endl;
  104. outfile << setw(20) << "Children" << setw(13) "School Fee" << setw(18)
  105. << "Water (gallons)" << setw(15) << "Water Charge" << endl;
  106. outfile << setw(20) << children << setw(13) school_fee << setw(18)
  107. << water << setw(15) << water_chrg << endl << endl;
  108. outfile << setw(26) << "Electric (kwh)" << setw(19) "Electric Charge" << setw(21)
  109. << "Sanitation Charge" << endl;
  110. outfile << setw(26) << electric << setw(19) elec_chrg << setw(21)
  111. << SAN_CHRG << endl << endl;
  112. outfile << "Total Charge: " << endl << endl;
  113. outfile << "Tax: " << endl << endl;
  114. outfile << "Balance Due: " << endl << endl;
  115.  
  116.  
  117. outfile.close ( );
  118. }
Last edited by alc6379; Nov 10th, 2004 at 7:42 pm. Reason: added [code] tags
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 715
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: program w/ switch AND nested if. six error messages

 
0
  #10
Nov 11th, 2004
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.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC