You are using a version without Ads of this website. Please, consider donating:

HELP PLEASE, CODE DUE IN 1 HOUR!

I have my entire code written for this assignment (which reads values from an input file) as well as the data set, but when I run it using the data set nothing happens and I have to use "control X + C" to stop running it. Can someone help me find what the problem is, and why no values are being displayed for this? I've spent hours on this code and still can't find the problem ... and it's due in an hour!

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119`` ``````#include #include #include #include using namespace std; const int SMALL = 30; // Cost to plant a small tree const int MED = 75; // Cost to plant a medium tree const int LARGE = 120; // Cost to plant a large tree const int FLATFEE = 100; // Cost of flat fee to remove tree/stump const int FEELESS = 10; // Cost of fee (per inch) for stumps with a diameter less than 6 inches const int FEEMORE = 15; // Cost of fee (per inch) for stumps with a diameter of 6 inches or more const int YARDMAINT = 25; // Cost (per hour) for general yard maintenance int main() { char charreader; // Used to input the first character of each line in the code char plantsize; // Used to input the plant sizes char codeL; // First letter of job code char codeN1; // First number of job code char codeN2; // Second number of job code char codeN3; // Third number of job code int smallcounter; // Counts number of small trees planted int medcounter; // Counts number of medium trees planted int largecounter; // Counts number of large trees planted int removecounter; // Counts number of trees being removed int stumpdiameter; // Diameter of stump being removed int lessthan6counter; // Counts number of trees being removed with a diameter of less than 6 inches int morethan6counter; // Counts number of trees being removed with a diameter of 6 or more inches double hours; // Number of hours spent doing general maintenance work double hoursB; // Only used if there is more than one line per job indiciating number of hours spent doing gnereal maintenance work double plantcost; // Total cost for trees to be planted for one whole job double removecost; // Total cost for trees and their stumps to be removed for one whole job double maintcost; // Total cost for general maintenance work for one whole job double jobtotal; // Total cost for one whole job double grandtotal; // Total cost for all jobs in the input file cout << "Dayton Flores - Assignment 7 - Section 1004" << endl; cout << " " << endl; cout << setw(28) << "TREE" << setw(16) << "MAINTAIN" << endl; cout << "JOB" << setw(14) << "PLANTING" << setw(13) << "REMOVAL" << setw(12) << "YARD" << setw(18) << "TOTAL" << endl; while(cin) { cin >> codeL >> codeN1 >> codeN2 >> codeN3; cin >> charreader; while(charreader != '*') { if(charreader = 'P') { cin >> charreader; while(charreader != '#') { if(charreader = 'S') { smallcounter++; } if(charreader = 'M') { medcounter++; } if(charreader = 'L') { largecounter++; } } } if(charreader = 'R') { cin >> removecounter; for(int i = 0; i < removecounter; i++) { cin >> stumpdiameter; if(stumpdiameter < 6) { lessthan6counter++; } if(stumpdiameter >= 6) { morethan6counter++; } } } if(charreader = 'M') { if(hours == 0) { cin >> hours; } if(hours > 0) { cin >> hoursB; hours += hoursB; } } if(charreader = '*') { plantcost = (smallcounter * SMALL) + (medcounter * MED) + (largecounter * LARGE); removecost = ((lessthan6counter + morethan6counter) * 100); maintcost = (YARDMAINT * hours); jobtotal = plantcost + removecost + maintcost; cout << fixed<< showpoint <

EDIT: It seems as though the very first "while(cin)" loop isn't even starting... I am running the program with the data set by using "./a.out < hw07data" after compiling it. Any suggestions?
Last edited on
Did you find that out by debugging? If not, you should try debugging to see if you can get any details about the program's state that help.
Last edited on
How do I debug it? I'm running this in Terminal on Mac OS X 10.8.5.
One problem I see is that you mess up the comparisons. For example:

 ``123`` ``````if(charreader = 'P') // this is an assignment, single equal sign if(charreader == 'P') // this is a comparison, double equal sign ``````

Thank you for the help! I changed them all and it's still giving me the same results! It's as if I'm running the program without using an input file the way I have to quit it from running even though nothing is being output!

I also rewrote the code except using "switch" statements, if you guys could possibly analyze... same results with this one!

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121`` ``````#include #include #include #include using namespace std; const int SMALL = 30; // Cost to plant a small tree const int MED = 75; // Cost to plant a medium tree const int LARGE = 120; // Cost to plant a large tree const int FLATFEE = 100; // Cost of flat fee to remove tree/stump const int FEELESS = 10; // Cost of fee (per inch) for stumps with a diameter less than 6 inches const int FEEMORE = 15; // Cost of fee (per inch) for stumps with a diameter of 6 inches or more const int YARDMAINT = 25; // Cost (per hour) for general yard maintenance int main() { char charreader; // Used to input the first character of each line in the code char plantsize; // Used to input the plant sizes char codeL; // First letter of job code char codeN1; // First number of job code char codeN2; // Second number of job code char codeN3; // Third number of job code int smallcounter; // Counts number of small trees planted int medcounter; // Counts number of medium trees planted int largecounter; // Counts number of large trees planted int removecounter; // Counts number of trees being removed int stumpdiameter; // Diameter of stump being removed int lessthan6counter; // Counts number of trees being removed with a diameter of less than 6 inches int morethan6counter; // Counts number of trees being removed with a diameter of 6 or more inches double hours; // Number of hours spent doing general maintenance work double hoursB; // Only used if there is more than one line per job indiciating number of hours spent doing gnereal maintenance work double plantcost; // Total cost for trees to be planted for one whole job double removecost; // Total cost for trees and their stumps to be removed for one whole job double maintcost; // Total cost for general maintenance work for one whole job double jobtotal; // Total cost for one whole job double grandtotal; // Total cost for all jobs in the input file cout << "Dayton Flores - Assignment 7 - Section 1004" << endl; cout << " " << endl; cout << setw(28) << "TREE" << setw(16) << "MAINTAIN" << endl; cout << "JOB" << setw(14) << "PLANTING" << setw(13) << "REMOVAL" << setw(12) << "YARD" << setw(18) << "TOTAL" << endl; while(cin) { cin >> codeL >> codeN1 >> codeN2 >> codeN3; cin >> charreader; while(charreader != '*') { switch(charreader) { case 'P': cin >> plantsize; while(plantsize != '#') { if(plantsize == 'S') { smallcounter++; } if(plantsize == 'M') { medcounter++; } if(plantsize == 'L') { largecounter++; } } break; case 'R': cin >> removecounter; for(int i = 0; i < removecounter; i++) { cin >> stumpdiameter; if(stumpdiameter < 6) { lessthan6counter++; } if(stumpdiameter >= 6) { morethan6counter++; } } break; case 'M': if(hours == 0) { cin >> hours; } if(hours > 0) { cin >> hoursB; hours += hoursB; } break; case '*': plantcost = (smallcounter * SMALL) + (medcounter * MED) + (largecounter * LARGE); removecost = ((lessthan6counter + morethan6counter) * 100); maintcost = (YARDMAINT * hours); jobtotal = plantcost + removecost + maintcost; cout << fixed<< showpoint <
Topic archived. No new replies allowed.

You are using a version without Ads of this website. Please, consider donating: