| | |
program w/ switch AND nested if. six error messages
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2004
Posts: 21
Reputation:
Solved Threads: 0
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
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
>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:
>doesn't the result of my switch and nested if statements define them?
Not in C++.
Your variable tells the compiler, "Here I am! I exist. Set aside storage for me." And you do it like so:
C++ Syntax (Toggle Plain Text)
int main() { int variable; // variable is now defined // ... }
Not in C++.
I'm here to prove you wrong.
•
•
Join Date: Nov 2004
Posts: 21
Reputation:
Solved Threads: 0
thank you so much!
C++ Syntax (Toggle Plain Text)
//*****************************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 ( ); }
Last edited by alc6379; Nov 10th, 2004 at 7:42 pm. Reason: added [code] tags
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.
![]() |
Other Threads in the C++ Forum
- Previous Thread: assignment needs a little help, well i do
- Next Thread: problem with Chars and Strings
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






