// Programmer: Dylan McDonald // Class & Section: CS 54, Section // Date: February 6, 2007 // Purpose: To figure out how badly you're getting ripped off // (to learn enums) #include /* for srand() and rand() */ #include /* for time() */ #include using namespace std; enum car {SAWDUST = 1, JALOPY, BEATUP, EXIT}; int main() { int i, carChoice, numCars, profit = 0; int numBeatups = 0, numJalopies = 0, numSawdusts = 0; bool carSold, exitLoop = false; /* Part II - master loop that keeps the program going */ while (!exitLoop) { /* Part I - show the menu & ask for the car type */ /* Part II added the exit option */ cout << "1) Sawdust 325i" << endl; cout << "2) Jalopy 2400" << endl; cout << "3) BeatupMobile ZX7" << endl; cout << "4) Exit" << endl; cout << "Which car do you want to enter into inventory? "; cin >> carChoice; /* Part I - switch the choice & report according to the type */ switch (carChoice) { /* ...for the Sawdust */ case SAWDUST: cout << "How many more Sawdust 325i's do we have? "; cin >> numCars; numSawdusts = numSawdusts + numCars; break; /* ...for the Jalopy */ case JALOPY: cout << "How many more Jalopy 2400's do we have? "; cin >> numCars; numJalopies = numJalopies + numCars; break; /* ...for the BeatupMobile */ case BEATUP: cout << "How many more BeatupMobile ZX7's do we have? "; cin >> numCars; numBeatups = numBeatups + numCars; break; /* ...for if the user wants to bail out */ case EXIT: exitLoop = true; break; /* ...for cars too good for this lot */ default: cout << "There exists no such car." << endl; break; } } /* Part II - give a final report to the user */ cout << "We have: " << endl << numSawdusts << " Sawdust 325i's" << endl << numJalopies << " Jalopy 2400's" << endl << numBeatups << " BeatupMobile ZX7's" << endl; /* Part III - find the profit */ /* start by initializing the random number generator */ srand(time(NULL)); /* ...for the Sawdusts */ for (i = 0; i < numSawdusts; i++) { carSold = rand() % 2; if (carSold) { profit = profit + (7300 - 50); } } /* ...for the Jalopies */ for (i = 0; i < numJalopies; i++) { carSold = rand() % 2; if (carSold) { profit = profit + (6600 - 22); } } /* ...for the BeatupMobiles */ for (i = 0; i < numBeatups; i++) { carSold = rand() % 2; if (carSold) { profit = profit + (9200 - 42); } } cout << "We can expect to make $" << profit << "." << endl; return 0; }