Prompt:
1. generate 3 random numbers
2. add 1 to inside count if the second random number is greater than the first random number and less than the third random number
3. add 1 to outside count if the second random number is less first random number
4. add 1 to outside count if the second random number is greater than the third random number
5. add 1 to loop count.
repeat step 1 to 5 until inside count + outside count = maximum count using a for loop
the best solution uses 1 multi-way if statement with compound conditions to determine when to add 1 to inside count and outside count
My attempt:
#include <ctime>
#include <iomanip>
#include <iostream>
#include <random>
#include <string>
using namespace std;
int main()
{
const int ubound = 99;
const int lbound = 10;
uniform_int_distribution<int> u(lbound, ubound);
int seed = 0;
//int seed = (int)time(nullptr);
default_random_engine e(seed);
int outside_count = 0;
int inside_count = 0;
int loop_count = 0;
int max_count = u(e);
int n1, n2, n3;
while (inside_count + outside_count < max_count)
{
n1 = u(e);
n2 = u(e);
n3 = u(e);
loop_count++;
cout << setw(3) << loop_count << ": (" << n1 << ", " << n2
<< ", " << n3 << ") inside:" << setw(2) << inside_count << " outside: " << setw(2) << outside_count << endl;
for (n2 = u(e); (n2 > n1 && n2 < n3); inside_count = inside_count + 1)
{
//inside_count = inside_count + 1;
cout << inside_count << endl;
}
{
for (n2; ((n2 < n1) || (n2 > n3)); outside_count = outside_count + 1)
cout << outside_count << endl;
}
/*else if ((n2 < n1) || (n2 > n3))
{
outside_count = outside_count + 1;
cout << outside_count << endl;
}
/*else if (n2 > n3)
{
outside_count = outside_count + 1;
cout << outside_count<<endl;
}
*/
loop_count = loop_count + 1;
cout << outside_count << endl;
cout << max_count << endl;
cout << inside_count;
}
system("pause");
return 0;
}
Can someone please help me?