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!
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
usingnamespace std;
constint SMALL = 30; // Cost to plant a small tree
constint MED = 75; // Cost to plant a medium tree
constint LARGE = 120; // Cost to plant a large tree
constint FLATFEE = 100; // Cost of flat fee to remove tree/stump
constint FEELESS = 10; // Cost of fee (per inch) for stumps with a diameter less than 6 inches
constint FEEMORE = 15; // Cost of fee (per inch) for stumps with a diameter of 6 inches or more
constint 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 <<setprecision(2);
cout << left << codeL << codeN1 << codeN2 << codeN3 << setw(4) << " $ " << right;
cout << setw(8) << plantcost << " $" << setw(9) << removecost << " $ " << setw(8) << maintcost << " $ " << setw(7) << jobtotal << endl;
smallcounter = 0;
medcounter = 0;
largecounter = 0;
lessthan6counter = 0;
morethan6counter = 0;
hours = 0;
}
}
grandtotal += jobtotal;
}
cout << "TOTAL" << setw(79) << grandtotal;
return 0;
}
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?
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!
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
usingnamespace std;
constint SMALL = 30; // Cost to plant a small tree
constint MED = 75; // Cost to plant a medium tree
constint LARGE = 120; // Cost to plant a large tree
constint FLATFEE = 100; // Cost of flat fee to remove tree/stump
constint FEELESS = 10; // Cost of fee (per inch) for stumps with a diameter less than 6 inches
constint FEEMORE = 15; // Cost of fee (per inch) for stumps with a diameter of 6 inches or more
constint 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 <<setprecision(2);
cout << left << codeL << codeN1 << codeN2 << codeN3 << setw(4) << " $ " << right;
cout << setw(8) << plantcost << " $" << setw(9) << removecost << " $ " << setw(8) << maintcost << " $ " << setw(7) << jobtotal << endl;
smallcounter = 0;
medcounter = 0;
largecounter = 0;
lessthan6counter = 0;
morethan6counter = 0;
hours = 0;
break;
}
}
grandtotal += jobtotal;
}
cout << "TOTAL" << setw(79) << grandtotal;
return 0;
}