Want more features on Pastebin? Sign Up, it's FREE!
Guest

Array problem

By: a guest on Nov 19th, 2012  |  syntax: C++  |  size: 1.19 KB  |  views: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <cstdlib>
  2. #include <ctime>
  3. #include <iostream>
  4. #include <unistd.h>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8.  
  9. void clear()
  10. {
  11.   cout<<"\033[2J\033[1;1H";
  12. }
  13.  
  14. int main()
  15. {
  16.   srand(time(0));
  17.  
  18.   die[5] = { (rand()%6)+1, (rand()%6)+1, (rand()%6)+1, (rand()%6)+1, (rand()%6)+1 };
  19.   int bet;
  20.  
  21.   ifstream a_file ("Score.txt");
  22.   if ( !a_file.is_open() ) {
  23.     clear();
  24.     cout<<"Score file could not be loaded.  Maybe file doesn't exist?\n";
  25.     return 0;
  26.   }
  27.  
  28.   int score;
  29.   a_file>> score;
  30.  
  31.   clear();
  32.   cout<<"How much would you like to bet?\nRemember, you only have $"<< score <<"!\nEnter your bet: ";
  33.   cin>> bet;
  34.  
  35.   if ( bet > score ) {
  36.     clear();
  37.     cout<<"You bet more money then you have!\n";
  38.     return 0;
  39.   }
  40.  
  41.   clear();
  42.   cout<<"Rolling...\n";
  43.   usleep(0.1 * 1000000);
  44.   cout<<"First die: " << die[0] <<"\n";
  45.   usleep(1.3 * 1000000);
  46.   cout<<"Second die: " << die[1] <<"\n";
  47.   usleep(0.3 * 1000000);
  48.   cout<<"Third die: " << die[2] <<"\n";
  49.   usleep(2 * 1000000);
  50.   cout<<"Fourth die: " << die[3] <<"\n";
  51.   usleep(0.3 *1000000);
  52.   cout<<"Fifth die: " << die[4] <<"\n";
  53.   usleep(1.2 * 1000000);
  54.   cout<<"Sixth die: " << die[5] <<"\n";
  55.  
  56.   return 0;
  57. }
clone this paste RAW Paste Data