Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- #include <sstream>
- #include <string>
- #include <vector>
- using namespace std;
- int main()
- {
- // Initialize and declear all Variables
- ifstream myinputstream;
- ofstream myoutputstream;
- char inputname[1024] = { '\0' };
- char outputname[1024] = { '\0' };
- char inFile[1024] = { '\0' };
- int i = 0; //number of tries
- const int maxtries = 2; //maximum number of tires
- int numlines = 0; //number of lines in a file
- const int minlines = 1; //minimum number of lines in the file
- const int maxlines = 5000; // maximum number of lines in the file
- int weight = 0; // weight of a coin
- int diameter = 0;
- //double diametermm = 0;
- //double weightgrams = 0;
- string weightstring;
- string diameterstring;
- string wholeline;
- int NNN = 0; // count line
- int count1 = 0;
- string usable;
- string match;
- string extrastuff;
- double measuringDiameter = 0.0;
- double measuringWeight = 0.0;
- int numNICKEL = 0;
- int numTWONIES = 0;
- int numLOONIES = 0;
- int numDIMES = 0;
- int numQUARTERS = 0;
- int numOTHER = 0;
- int nickle = 0;
- int twonies = 0;
- int loonies = 0;
- int dimes = 0;
- int quarters = 0;
- int numRollsNickels = 0;
- int numRollsDimes = 0;
- int numRollsQuarter = 0;
- int numRollsLoonies = 0;
- int numRollsToonies = 0;
- double weightBentContainer = 0.0;
- double totalBentCoinWeight = 0.0;
- int numBentContainer = 0;
- double weightOtherContainer = 0.0;
- int totalOtherCoinsNum = 0;
- int numOtherContainer = 0;
- double totalOtherCoinWeight = 0.0;
- //declear constants
- //nickel max and min weight and diameter
- const double minNICKELweight = 3.60;
- const double maxNICKELweight = 4.30;
- const double minNICKELdiameter = 20.2;
- const double maxNICKELdiameter = 20.8;
- //dime max and min weight and diameter
- const double minDIMEweight = 1.30;
- const double maxDIMEweight = 2.20;
- const double minDIMEdiameter = 17.3;
- const double maxDIMEdiameter = 18.7;
- //quarter max and min weight and diameter
- const double minQUARTERweight = 4.00;
- const double maxQUARTERweight = 4.80;
- const double minQUARTERdiameter = 22.80;
- const double maxQUARTERdiameter = 24.60;
- //loonie max and min weight and diameter
- const double minLOONIEweight = 6.50;
- const double maxLOONIEweight = 7.50;
- const double minLOONIEdiameter = 25.00;
- const double maxLOONIEdiameter = 27.00;
- //toonie max and min weight and diameter
- const double minTWONIEweight = 6.75;
- const double maxTWONIEweight = 7.85;
- const double minTWONIEdiameter = 26.90;
- const double maxTWONIEdiameter = 29.10;
- //Coins per Role
- const int NICKELSPERROLE = 40;
- const int DIMESPERROLE = 50;
- const int QUARTERSPERROLE = 40;
- const int LOONIESPERROLE = 25;
- const int TOONIESPERROLE = 25;
- const double maxBENTcontainerWEIGHT = 100.0;
- const double maxOTHERcontainerWEIGHT = 200.0;
- double coinWEIGHT = 0.0;
- double coinDIAMETER = 0.0;
- double otherWEIGHT = 0.0;
- cout.setf(ios::fixed);
- cout.setf(ios::showpoint);
- do
- {
- cout << "Type the name of the input file containing sensor readings:\n";
- cin >> inputname;
- myinputstream.open(inputname);
- if (myinputstream.fail())
- {
- cerr << "ERROR: file " << inputname << " could not be opened for input" << endl;
- i++;
- }
- if (i > maxtries)
- {
- cout << "ERROR: You exceeded maximum number of tries allowed \nwhile entering the input file name";
- return 1;
- }
- } while (myinputstream.fail() && i <= maxtries);
- i = 0; //reset i back to zero
- //error for outputfiles
- do
- {
- cout << "Type the name of the output file which will hold the simulation results: \n";
- cin >> outputname;
- myoutputstream.open(outputname, ios::in);
- if (myoutputstream.fail())
- {
- cerr << "ERROR: file " << outputname << " could not be opened for output" << endl;
- i++;
- }
- if (i > maxtries)
- {
- cerr << "ERROR: You exceeded maximum number of tries allowed \nwhile entering the output file name";
- return 1;
- }
- } while (myoutputstream.fail() && i <= maxtries);
- if (!(myinputstream >> numlines))
- {
- if (myinputstream.eof())
- {
- cerr << "ERROR: Input data file is empty" << endl;
- myinputstream.close();
- myoutputstream.close();
- return 1;
- }
- else
- {
- cerr << "ERROR: First piece of data in the file is not an integer\n";
- myinputstream.close();
- myoutputstream.close();
- return 1;
- }
- }
- if (numlines < minlines || numlines > maxlines)
- {
- cerr << "ERROR: The number of sensor readings is out of range" << endl;
- myinputstream.close();
- return 1;
- }
- while(NNN <= numlines)
- {
- NNN++;
- while (!myinputstream.eof()) { //If all of the above runs fine, it will begin processing the data of the text file. This while loop runs only until there are no lines left in the code
- getline(myinputstream, wholeline, '\n'); //This begins processing information through the getfile function
- if (wholeline.empty()) { //This will skip any empty lines in the code before it adds the line to the count
- continue;
- }
- NNN++; //This will display the amount of lines
- /*cout << wholeline << '\n';*/ //This line is used only to test and check for any errors in each line
- istringstream iss(wholeline);
- getline(iss, weightstring, ' '); //This will process our value for the weight of the coin. The value should be within the sensor reading ( 0 <= weight <= 255)
- stringstream weightstringtoint(weightstring);
- weightstringtoint >> weight; //This will convert the string into an integer
- if (weightstring.empty())
- { //If there is no value read from the line for weight, it will run this error
- cerr << "ERROR: No more data" << endl;
- cerr << "Simulation completed early before line " << NNN << " of input" << endl;
- continue;
- }
- if (!weight) { //If the first value read on the line is not an integer (i.e. a value with decimals, letters, etc.), it will run this error
- cerr << "ERROR: Weight sensor value read on line " << NNN << " is not an integer" << endl;
- cerr << "Simulation terminated early: Please correct your data file" << endl;
- continue;
- }
- getline(iss, diameterstring, ' '); //The second value read on the line will be the diameter of the coin. The value should also be within the sensor reading (0 <= diameter <= 255)
- stringstream diametertoint(diameterstring);
- diametertoint >> diameter; //This will convert the string into an integer
- if (diameterstring.empty()) { //If there is no second value read on the line for diameter, it will run this error
- cerr << "ERROR: Weight sensor measurement only" << endl;
- cerr << "Ignoring line " << NNN << " of the input file" << endl;
- continue;
- }
- if (!diameter) { //If the value read on the line is not an integer (i.e. a value with decimals, letters, etc.), it will run this error
- cerr << "ERROR: Diameter sensor value read on line " << NNN << " is not an integer" << endl;
- cerr << "Simulation terminated early: Please correct your data file" << endl;
- continue;
- }
- getline(iss, usable, ' '); //The third value read on the line will determine whether the coin is bent or still usable, with the only texts allowed being "bent" and "usable"
- if (usable.empty()) { //If there is no third value read on the line for bent, it will run this error
- cerr << "ERROR: Weight and diameter sensor measurements only" << endl;
- cerr << "Ignoring line " << NNN << " of the input file" << endl;
- continue;
- }
- if (usable != "bent" && usable != "usable") { //If the value read on the line is neither "bent" or "usable", it will run this error
- cerr << "ERROR: Result of test to determine if coin is bent at line " << NNN << " is invalid" << endl;
- cerr << "Ignoring this line of data" << endl;
- continue;
- }
- getline(iss, match, ' '); //The fourth value on the line will determine whether the coin has any matches with canadian coins, named faceimage. The only values that it should read is "BothMatch", "OneMatch", or "NoMatch"
- if (match.empty()) { //If there is no fourth value read on the line for faceimage, it will run this error
- cerr << "ERROR: Weight and diameter sensor measurements and bent string only" << endl;
- cerr << "Ignoring line " << NNN << " of the input file" << endl;
- continue;
- }
- if (match != "BothMatch" && match != "OneMatch" && match != "NoMatch") { //If the value read on this line is neither "BothMatch", "OneMatch", or "NoMatch", it will run this error
- cerr << "ERROR: image processing result at line " << NNN << " is invalid" << endl;
- cerr << "Ignoring this line of data" << endl;
- continue;
- }
- getline(iss, extrastuff, ' '); //This will read if there is any fifth value on the line that we do not want, named extrastuff
- if (!extrastuff.empty()) { //If there is a fifth value read on the line, it will run this error
- cerr << "ERROR: Extra data at line " << NNN << ". Ignoring extra data" << endl;
- extrastuff.clear(); //Resets the string value
- continue;
- }
- if (weight < 0 || weight > 255 || diameter < 0 || diameter > 255) { //If either the weight or diameter are outside of the sensor reading ( 0 <= weight/diameter <= 255), it will run this error
- cerr << "ERROR: Sensor reading is out of range, ignoring line " << NNN << " in the input file" << endl;
- continue;
- }
- coinWEIGHT = static_cast<double>(weight) * ((double)(2) / (double)(51));
- coinDIAMETER = static_cast<double>(diameter) * ((double)(30) / (double)(255) + (double)(10));
- cout.precision(2);
- if (usable == "usable")
- {
- if (match == "BothMatch")
- {
- if ((coinWEIGHT >= minNICKELweight && coinWEIGHT <= maxNICKELweight) && (coinDIAMETER >= minNICKELdiameter && coinDIAMETER <= maxNICKELdiameter))
- {
- numNICKEL++;
- cout << "The Coin Sorter has sent one coin to the nickels wrapper" << endl;
- if (numNICKEL == NICKELSPERROLE)
- {
- numRollsNickels++;
- numNICKEL = 0;
- cout << "The nickel wrapper is now full" << endl;
- cout << "The nickel wrapper has now been replaced" << endl;
- continue
- }
- else
- {
- cout << "There are now " << numNICKEL << " in the nickels wrapper" << endl;
- }
- }
- else if ((coinWEIGHT >= minDIMEweight && coinWEIGHT <= maxDIMEweight) && (coinDIAMETER >= minDIMEdiameter && coinDIAMETER <= maxDIMEdiameter))
- {
- numDIMES++;
- cout << "The Coin Sorter has sent one coin to the dimes wrapper" << endl;
- if (numDIMES == DIMESPERROLE)
- {
- numRollsDimes++;
- numDIMES = 0;
- cout << "The dime wrapper is now full" << endl;
- cout << "The dime wrapper has now been replaced" << endl;
- break;
- }
- else
- {
- cout << "There are now " << numDIMES << " coins in the dimes wrapper" << endl;
- }
- }
- else if ((coinWEIGHT >= minQUARTERweight && coinWEIGHT <= maxQUARTERweight) && (coinDIAMETER >= minQUARTERdiameter && coinDIAMETER <= maxQUARTERdiameter))
- {
- numQUARTERS++;
- cout << "The Coin Sorter has sent one coin to the quarters wrapper" << endl;
- if (numQUARTERS == QUARTERSPERROLE)
- {
- numRollsQuarter++;
- numQUARTERS = 0;
- cout << "The quarter wrapper is now full" << endl;
- cout << "The quarter wrapper has now been replaced" << endl;
- }
- else
- {
- cout << "There are now " << numQUARTERS << " in the quarters wrapper" << endl;
- }
- }
- else if ((coinWEIGHT >= minLOONIEweight && coinWEIGHT <= maxLOONIEweight) && (coinDIAMETER >= minLOONIEdiameter && coinDIAMETER <= maxLOONIEdiameter))
- {
- numLOONIES++;
- cout << "The Coin Sorter has sent one coin to the loonies wrapper" << endl;
- if (numLOONIES == LOONIESPERROLE)
- {
- numRollsLoonies++;
- numLOONIES = 0;
- cout << "The loonie wrapper is now full" << endl;
- cout << "The loonie wrapper has now been replaced" << endl;
- }
- else
- {
- cout << "There are now " << numLOONIES << " in the loonies wrapper" << endl;
- }
- }
- else if ((coinWEIGHT >= minTWONIEweight && coinWEIGHT <= maxTWONIEweight) && (coinDIAMETER >= minTWONIEdiameter && coinDIAMETER <= maxTWONIEdiameter))
- {
- numTWONIES++;
- cout << "The Coin Sorter has sent one coin to the toonies wrapper" << endl;
- if (numTWONIES == TOONIESPERROLE)
- {
- numRollsToonies++;
- numTWONIES = 0;
- cout << "The toonie wrapper is now full" << endl;
- cout << "The toonie wrapper has now been replaced" << endl;
- }
- else
- {
- cout << "There are now " << numTWONIES << " in the toonies wrapper" << endl;
- }
- }
- }
- else
- {
- totalOtherCoinWeight += coinWEIGHT;
- totalOtherCoinsNum++;
- if (weightOtherContainer > maxOTHERcontainerWEIGHT)
- {
- weightOtherContainer = 0;
- weightOtherContainer += coinWEIGHT;
- numOtherContainer++;
- cout << "This coin does not fit in the other coin container" << endl;
- cout << "The other coin container has been replaced" << endl;
- cout << "The coin in the new other coin container weighs " << weightOtherContainer << " grams" << endl;
- }
- else
- {
- weightOtherContainer += coinWEIGHT;
- cout << "The Coin Sorter has sent this coin to the other coin container" << endl;
- cout << "The coins in the other coin container now weigh " << weightOtherContainer << " grams" << endl;
- }
- }
- }
- if (usable == "bent")
- {
- weightBentContainer += coinWEIGHT;
- totalBentCoinWeight += coinWEIGHT;
- if (weightBentContainer > maxBENTcontainerWEIGHT)
- {
- weightBentContainer = 0;
- weightBentContainer += coinWEIGHT;
- numBentContainer++;
- cout << "This coin does not fit in the bent coin container" << endl;
- cout << "The bent coin container has been replaced" << endl;
- cout << "The coin in the new bent coin container weighs " << weightBentContainer << " grams" << endl;
- }
- cout << "The Coin Sorter has sent this coin to the bent coin container" << endl;
- cout << "The coins in the bent coin container now weighs " << weightBentContainer << " grams" << endl;
- }
- /*if (!(myinputstream >> weight))
- {
- if (myinputstream.eof())
- {
- cerr << "ERROR: No more data" << endl;
- cerr << "Simulation completed early before line " << NNN << " of input" << endl;
- break;
- }
- else
- {
- cerr << "ERROR: Weight sensor value read on line " << NNN << " is not an integer" << endl;
- cerr << "Simulation terminated early : Please correct your data file" << endl;
- return 1;
- }
- }
- char space;
- space = myinputstream.peek();
- while (space == ' ' || space == '\t')
- {
- space = myinputstream.get();
- }
- if (space == '\n') continue;
- if (space == '\n')
- {
- cout << "ERROR: Weight sensor measurement only" << endl;
- cout << "ERROR: Ignore line " << NNN << " of the input file" << endl;
- continue;
- }
- if (!(myinputstream >> diameter))
- {
- cerr << "ERROR: Diameter sensor value read on line " << NNN << " is not an integer" << endl;
- cerr << "Simulation terminated early : Please correct your data file" << endl;
- return 1;
- }
- while (space == ' ' || space == '\t')
- {
- myinputstream.get();
- }
- if (space == '\n')
- {
- cerr << "ERROR: Weight and diameter sensor measurements only" << endl;
- cerr << "Ignoring line " << NNN << " of the input file" << endl;
- return 1;
- }
- myinputstream >> usable;
- if (usable != "bent" && usable != "usable")
- {
- cerr << "ERROR: Result of test to determine if coin is bent at line " << NNN << " is invalid" << endl;
- cerr << "Ignoring this line of data" << endl;
- while (!(myinputstream.peek() == '\n'))
- {
- myinputstream.get();
- }
- continue;
- }
- while (space == ' ' || space == '\t')
- {
- myinputstream.get();
- }
- if (space == '\n');
- {
- cerr << "ERROR: Weight and diameter sensor measurements and bent string only" << endl;
- cerr << "Ignoring line " << NNN << " of the input file" << endl;
- continue;
- }
- myinputstream >> match;
- if (match != "BothMatch" && match != "OneMatch" && match != "NoMatch")
- {
- cerr << "ERROR: image processing result at line " << NNN << " is invalid" << endl;
- cerr << "Ignoring this line of data" << endl;
- continue;
- }
- while (space == ' ' || space == '\t');
- {
- myinputstream.get();
- if (space != '\n' && space == '\t' && space != ' ')
- {
- cerr << "ERROR: Extra data at line " << NNN << ". Ignoring extra data" << endl;
- }
- while (space != ' ' && space == '\n');
- {
- myinputstream.get();
- }
- }
- coinWEIGHT = static_cast<double>(weight) * ((double)(2) / (double)(51));
- coinDIAMETER = static_cast<double>(diameter) * ((double)(30) / (double)(255) + (double)(10));
- cout.precision(2);
- cout << " why is this not working";
- if ((coinWEIGHT >= minNICKELweight && coinWEIGHT <= maxNICKELweight) && (coinDIAMETER >= minNICKELdiameter && coinDIAMETER <= maxNICKELdiameter))
- {
- numNICKEL++;
- cout << "The Coin Sorter has sent one coin to the nickels wrapper" << endl;
- if (numNICKEL == NICKELSPERROLE)
- {
- numRollsNickels++;
- numNICKEL = 0;
- cout << "The nickel wrapper is now full" << endl;
- cout << "The nickel wrapper has now been replaced" << endl;
- }
- else
- {
- cout << "There are now " << numNICKEL << " in the nickels wrapper" << endl;
- }
- }
- else if ((coinWEIGHT >= minDIMEweight && coinWEIGHT <= maxDIMEweight) && (coinDIAMETER >= minDIMEdiameter && coinDIAMETER <= maxDIMEdiameter))
- {
- numDIMES++;
- cout << "The Coin Sorter has sent one coin to the dimes wrapper" << endl;
- if (numDIMES == DIMESPERROLE)
- {
- numRollsDimes++;
- numDIMES = 0;
- cout << "The dime wrapper is now full" << endl;
- cout << "The dime wrapper has now been replaced" << endl;
- break;
- }
- else
- {
- cout << "There are now " << numDIMES << " coins in the dimes wrapper" << endl;
- }
- }
- else if ((coinWEIGHT >= minQUARTERweight && coinWEIGHT <= maxQUARTERweight) && (coinDIAMETER >= minQUARTERdiameter && coinDIAMETER <= maxQUARTERdiameter))
- {
- numQUARTERS++;
- cout << "The Coin Sorter has sent one coin to the quarters wrapper" << endl;
- if (numQUARTERS == QUARTERSPERROLE)
- {
- numRollsQuarter++;
- numQUARTERS = 0;
- cout << "The quarter wrapper is now full" << endl;
- cout << "The quarter wrapper has now been replaced" << endl;
- }
- else
- {
- cout << "There are now " << numQUARTERS << " in the quarters wrapper" << endl;
- }
- }
- else if ((coinWEIGHT >= minLOONIEweight && coinWEIGHT <= maxLOONIEweight) && (coinDIAMETER >= minLOONIEdiameter && coinDIAMETER <= maxLOONIEdiameter))
- {
- numLOONIES++;
- cout << "The Coin Sorter has sent one coin to the loonies wrapper" << endl;
- if (numLOONIES == LOONIESPERROLE)
- {
- numRollsLoonies++;
- numLOONIES = 0;
- cout << "The loonie wrapper is now full" << endl;
- cout << "The loonie wrapper has now been replaced" << endl;
- }
- else
- {
- cout << "There are now " << numLOONIES << " in the loonies wrapper" << endl;
- }
- }
- else if ((coinWEIGHT >= minTWONIEweight && coinWEIGHT <= maxTWONIEweight) && (coinDIAMETER >= minTWONIEdiameter && coinDIAMETER <= maxTWONIEdiameter))
- {
- numTWONIES++;
- cout << "The Coin Sorter has sent one coin to the toonies wrapper" << endl;
- if (numTWONIES == TOONIESPERROLE)
- {
- numRollsToonies++;
- numTWONIES = 0;
- cout << "The toonie wrapper is now full" << endl;
- cout << "The toonie wrapper has now been replaced" << endl;
- }
- else
- {
- cout << "There are now " << numTWONIES << " in the toonies wrapper" << endl;
- }
- }
- string x = " "; //whatever is in the file
- string y;
- i = 0;
- while (getline(myinputstream, x))
- {
- vector<string> vec;
- stringstream buf(x);
- while (buf >> y)
- {
- vec.push_back(y);
- }
- switch (vec.size())
- {
- case 0:
- {
- if (myinputstream.eof())
- {
- cerr << "ERROR: No more data" << endl;
- cerr << "Simulation completed early before line " << NNN << " of input" << endl;
- break;
- }
- else
- {
- continue;
- }
- }
- break;
- case 1:
- {
- int weight = stoi(vec.at(0));
- try
- {
- int weight = stoi(vec.at(0));
- }
- catch (...)
- {
- cerr << "ERROR: Weight sensor value read on line " << NNN << " is not an integer" << endl;
- cerr << "Simulation terminated early : Please correct your data file" << endl;
- NNN++;
- }
- if (!(weight <= 255 && weight >= 0))
- {
- cerr << "ERROR: Sensor reading out of range, ignoring line " << NNN << " in the input file" << endl;
- }
- else
- {
- cout << "ERROR: Weight sensor measurement only" << endl;
- cout << "ERROR: Ignore line " << NNN << " of the input file" << endl;
- NNN++;
- }
- } break;
- case 2:
- {
- int diameter = stoi(vec.at(1));
- try
- {
- int diameter = stoi(vec.at(1));
- }
- catch (...)
- {
- cerr << "ERROR: Diameter sensor value read on line " << NNN << " is not an integer" << endl;
- cerr << "Simulation terminated early : Please correct your data file" << endl;
- NNN++;
- }
- if (!(diameter <= 255 && diameter >= 0))
- {
- cerr << "ERROR: Sensor reading out of range, ignoring line " << NNN << " in the input file" << endl;
- NNN++;
- }
- else
- {
- cerr << "ERROR: Weight and diameter sensor measurements only" << endl;
- cerr << "Ignoring line " << NNN << " of the input file" << endl;
- NNN++;
- }
- }
- break;
- case 3:
- {
- string usable = vec.at(2);
- if (usable != "bent" && usable != "usable")
- {
- cerr << "ERROR: Result of test to determine if coin is bent at line " << NNN << " is invalid" << endl;
- cerr << "Ignoring this line of data" << endl;
- NNN++;
- }
- else
- {
- cerr << "ERROR: Weight and diameter sensor measurements and bent string only" << endl;
- cerr << "Ignoring line " << NNN << " of the input file" << endl;
- NNN++;
- }
- }
- break;
- case 4:
- {
- string match = vec.at(3);
- if (match != "BothMatch" && match != "OneMatch" && match != "NoMatch")
- {
- cerr << "ERROR: image processing result at line " << NNN << " is invalid" << endl;
- cerr << "Ignoring this line of data" << endl;
- NNN++;
- }
- else
- {
- NNN++;
- coinWEIGHT = static_cast<double>(weight) * ((double)(2) / (double)(51));
- coinDIAMETER = static_cast<double>(diameter) * ((double)(30) / (double)(255) + (double)(10));
- cout.precision(2);
- if (usable == "usable")
- {
- if (match == "BothMatch")
- {
- if ((coinWEIGHT >= minNICKELweight && coinWEIGHT <= maxNICKELweight) && (coinDIAMETER >= minNICKELdiameter && coinDIAMETER <= maxNICKELdiameter))
- {
- numNICKEL++;
- cout << "The Coin Sorter has sent one coin to the nickels wrapper" << endl;
- if (numNICKEL == NICKELSPERROLE)
- {
- numRollsNickels++;
- numNICKEL = 0;
- cout << "The nickel wrapper is now full" << endl;
- cout << "The nickel wrapper has now been replaced" << endl;
- }
- else
- {
- cout << "There are now " << numNICKEL << " in the nickels wrapper" << endl;
- }
- }
- else if ((coinWEIGHT >= minDIMEweight && coinWEIGHT <= maxDIMEweight) && (coinDIAMETER >= minDIMEdiameter && coinDIAMETER <= maxDIMEdiameter))
- {
- numDIMES++;
- cout << "The Coin Sorter has sent one coin to the dimes wrapper" << endl;
- if (numDIMES == DIMESPERROLE)
- {
- numRollsDimes++;
- numDIMES = 0;
- cout << "The dime wrapper is now full" << endl;
- cout << "The dime wrapper has now been replaced" << endl;
- break;
- }
- else
- {
- cout << "There are now " << numDIMES << " coins in the dimes wrapper" << endl;
- }
- }
- else if ((coinWEIGHT >= minQUARTERweight && coinWEIGHT <= maxQUARTERweight) && (coinDIAMETER >= minQUARTERdiameter && coinDIAMETER <= maxQUARTERdiameter))
- {
- numQUARTERS++;
- cout << "The Coin Sorter has sent one coin to the quarters wrapper" << endl;
- if (numQUARTERS == QUARTERSPERROLE)
- {
- numRollsQuarter++;
- numQUARTERS = 0;
- cout << "The quarter wrapper is now full" << endl;
- cout << "The quarter wrapper has now been replaced" << endl;
- }
- else
- {
- cout << "There are now " << numQUARTERS << " in the quarters wrapper" << endl;
- }
- }
- else if ((coinWEIGHT >= minLOONIEweight && coinWEIGHT <= maxLOONIEweight) && (coinDIAMETER >= minLOONIEdiameter && coinDIAMETER <= maxLOONIEdiameter))
- {
- numLOONIES++;
- cout << "The Coin Sorter has sent one coin to the loonies wrapper" << endl;
- if (numLOONIES == LOONIESPERROLE)
- {
- numRollsLoonies++;
- numLOONIES = 0;
- cout << "The loonie wrapper is now full" << endl;
- cout << "The loonie wrapper has now been replaced" << endl;
- }
- else
- {
- cout << "There are now " << numLOONIES << " in the loonies wrapper" << endl;
- }
- }
- else if ((coinWEIGHT >= minTWONIEweight && coinWEIGHT <= maxTWONIEweight) && (coinDIAMETER >= minTWONIEdiameter && coinDIAMETER <= maxTWONIEdiameter))
- {
- numTWONIES++;
- cout << "The Coin Sorter has sent one coin to the toonies wrapper" << endl;
- if (numTWONIES == TOONIESPERROLE)
- {
- numRollsToonies++;
- numTWONIES = 0;
- cout << "The toonie wrapper is now full" << endl;
- cout << "The toonie wrapper has now been replaced" << endl;
- }
- else
- {
- cout << "There are now " << numTWONIES << " in the toonies wrapper" << endl;
- }
- }
- }
- else
- {
- totalOtherCoinWeight += coinWEIGHT;
- totalOtherCoinsNum++;
- if (weightOtherContainer > maxOTHERcontainerWEIGHT)
- {
- weightOtherContainer = 0;
- weightOtherContainer += coinWEIGHT;
- numOtherContainer++;
- cout << "This coin does not fit in the other coin container" << endl;
- cout << "The other coin container has been replaced" << endl;
- cout << "The coin in the new other coin container weighs " << weightOtherContainer << " grams" << endl;
- }
- else
- {
- weightOtherContainer += coinWEIGHT;
- cout << "The Coin Sorter has sent this coin to the other coin container" << endl;
- cout << "The coins in the other coin container now weigh " << weightOtherContainer << " grams" << endl;
- }
- }
- }
- if(usable == "bent")
- {
- weightBentContainer += coinWEIGHT;
- totalBentCoinWeight += coinWEIGHT;
- if (weightBentContainer > maxBENTcontainerWEIGHT)
- {
- weightBentContainer = 0;
- weightBentContainer += coinWEIGHT;
- numBentContainer++;
- cout << "This coin does not fit in the bent coin container" << endl;
- cout << "The bent coin container has been replaced" << endl;
- cout << "The coin in the new bent coin container weighs " << weightBentContainer << " grams" << endl;
- }
- cout << "The Coin Sorter has sent this coin to the bent coin container" << endl;
- cout << "The coins in the bent coin container now weighs " << weightBentContainer << " grams" << endl;
- }
- }
- } break;
- default:
- {
- cerr << "ERROR: Extra data at line " << NNN << ". Ignoring extra data" << endl;
- NNN++;
- continue;
- }
- break;
- }
- }*/
- }
- }
- cout << endl << endl << endl;
- cout << "SUMMARY" << endl;
- cout << "The Coin Sorter made " << numRollsNickels << " rolls of nickels." << endl;
- cout << " There are " << numNICKEL << " nickels in the partially full roll." << endl;
- cout << "The Coin Sorter made " << numRollsDimes << " rolls of dimes." << endl;
- cout << " There are " << numDIMES << " dimes in the partially full roll." << endl;
- cout << "The Coin Sorter made " << numRollsQuarter << " rolls of quarters." << endl;
- cout << " There are " << numQUARTERS << " quarters in the partially full roll." << endl;
- cout << "The Coin Sorter made " << numRollsLoonies << " rolls of loonies." << endl;
- cout << " There are " << numLOONIES << " loonies in the partially full roll." << endl;
- cout << "The Coin Sorter made " << numRollsToonies << " rolls of toonies." << endl;
- cout << " There are " << numTWONIES << " toonies in the partially full roll." << endl;
- cout << "The Coin Sorter processed " << totalOtherCoinsNum << " other coins." << endl;
- cout << " The other coins completely filled " << numOtherContainer << " containers" << endl;
- cout << " There were " << numOTHER << " other coins in the partially full container" << endl;
- cout << " The total weight of the other coins was " << fixed << setprecision(3) << otherWEIGHT << " grams" << endl;
- cout << "The Coin Sorter processed " << fixed << setprecision(4) << totalBentCoinWeight << " g of bent coins" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement