# public redono / DailyProg135Easy.cpp Created 2013-08-12

Dailyprogrammer 135, properly indented this time.

DailyProg135Easy.cpp
C++
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 `#include #include #include #include #include #include #include #include  using namespace std; int nrand(int n) /* ** I have to admit, I cheated a bit here.This is taken from Accelerated C++,** but I wanted a fair way to make a random number. Because Rand isn't truly** random, there could be a difference in distribution if you simply took ** rand()%n. The rest I came up with myself. The reasoning of nrand is ** quite simple, if people want I can explain the reasoning.*/ { if (n <= 0 || n > RAND_MAX){ throw domain_error("Argument to nrand is out of range"); }  const int bucket_size = RAND_MAX / n; int r; do { r = rand() / bucket_size; } while (r >= n);  return r;} vector make_sum_numbers(const vector& numbers){ vector nums_in_sum; int i = 0; while(i<4){ nums_in_sum.push_back(numbers[nrand(numbers.size())]); ++i; } return nums_in_sum;} vector make_sum_operator(const vector& operators){ vector opers_in_sum; int i = 0; while (i<3){ opers_in_sum.push_back(operators[nrand(operators.size())]); ++i; } return opers_in_sum;} int solve_sum(vector sum_numbers, vector sum_operators, const vector& operators){ for(size_t i = 0; i operators = {"*", "+", "-"}; int min, max; cin>>min>>max;  if(min<0||max<0||(min==max)){ throw domain_error("Min/max: out of range"); return 1; }  vector numbers; int current = min;  while (current <= max){ numbers.push_back(current); ++current; }  while(true){ //entering the loop to keep going, break with EOF.  //Took me a while to figure this out: seeding the rng //before the makeloops because it would return the same number //every time if seeded inside. unsigned seed = static_cast(time(0)); srand(seed); vector sumNumbers = make_sum_numbers(numbers); vector sumOperators = make_sum_operator(operators);  for(int i = 0; i<7; ++i) { cout<<((i%2 == 0)?(to_string(sumNumbers[i/2])):(sumOperators[i/2]))<<" "; } cout<>useranswer)){ break; } while(useranswer!=solution){ cout<<"Try again!"<>useranswer; } time_t t2 = time(0); double time_taken = (double)(t2) - (double)(t1); cout<<"Good job! It took you "<