Guest User

Printer error generator.

a guest
Nov 9th, 2015
3,712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. //I'm fairly new to C++, please excuse the bad code. Just put this program into your compiler of choice, and let the hilarity ensue!
  2. #include <iostream>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <ctime>
  6.  
  7. using namespace std;
  8.  
  9. int random(int min, int max); //range : [min, max)
  10.  
  11. int main()
  12. {
  13.     string noun [10] = {"paper ", "tray ", "user ", "button ", "ink ", "toner ", "rack ", "spooler ", "printer ", "feeder "};
  14.     string fault [10] = {"jam", "error", "fault", "overload", "spill", "failure", "spill", "low ", "leak ", "malfunction "};
  15.     string action [10] = {"remove ", "reset ", "recalibrate ", "push ", "adjust ", "reload ", "dislodge ", "insert ", "retrieve ", "feed "};
  16.     bool keepgoing = true;
  17.     char ch;
  18.     while (keepgoing == true)
  19.     {
  20.         for(int i = 0; i < 10; i++)
  21.         {
  22.             cout << "Error: ";
  23.             cout << noun[random(0, 10)];
  24.             cout << fault[random(0,10)] << ": ";
  25.             cout << "Please ";
  26.             cout << action[random(0,10)];
  27.             cout << noun[random(0, 10)] << endl;
  28.         }
  29.         cout << endl << "Press enter to generate more error messages";
  30.         cin.get(ch);
  31.        
  32.     }
  33.     return 0;
  34. }
  35. //note to self: learn what this actually does.
  36. int random(int min, int max) //range : [min, max)
  37. {
  38.    static bool first = true;
  39.    if ( first )
  40.    {  
  41.       srand(time(NULL)); //seeding for the first time only!
  42.       first = false;
  43.    }
  44.    return min + rand() % (max - min);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment