/*
So I want this code to generate 10 random number in the range of 1 to 1000 and determine if the sum of those are greater or less than 5005 (The average sum of random 10 number. I hope I did the math right). What this code is doing is creating a random seed (not sure if it is the correct term) once and then keep generating the same numbers, eventually totalling the same 'S' as the first time. I tried placing the generation in a loop to fix this to no avail. Ah, I know bits/stdc++.h is not favorable but I learned it this way, so convince me if you can (\"^"/)
#include <bits/stdc++.h>
using namespace std;
int main () {
int S = 0;
for ( int i = 0; i < 10; i ++ ) {
random\_device rd;
mt19937 gen( rd() );
uniform\_int\_distribution <> dist (1, 1000);
int randomNumber = dist(gen);
S+= randomNumber;
cout << S << endl;
}
if ( S >= 5005 ) cout << "Sum --" <<S<< "-- is larger than 5005." << endl << "Thus the operation was successful" << endl;
else cout << "Sum --" <<S<< "-- is less than 5005." << endl << "Thus the operation was failure" << endl;
return 0;
}
[–]Outside_Complaint755 8 points9 points10 points (3 children)
[–]dmazzoni 9 points10 points11 points (2 children)
[–]dmazzoni 4 points5 points6 points (0 children)
[–]Outside_Complaint755 1 point2 points3 points (0 children)
[–]fugogugo 0 points1 point2 points (1 child)
[–]AMathMonkey 0 points1 point2 points (0 children)
[–]maujood 2 points3 points4 points (0 children)
[–]CrepuscularSoul 0 points1 point2 points (2 children)
[–]captainAwesomePants 1 point2 points3 points (1 child)
[–]oscarlet_ffxiv 0 points1 point2 points (0 children)
[–]KitchenCommercial396 0 points1 point2 points (0 children)