Matrix?

How can I have an output of the number of times the calculation has gone through?

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
 #include <iostream>
#include <cstdlib>
#include <time.h>

using namespace std;

int main() {
	cout << "Enter the upper bound: \n";
	int NumTries;
	cin >> NumTries;
		cout << "Enter Bound(1): \n";
		int num, div, wins{};
		cin >> num;
			cout << "Enter Bound(2): \n";
			cin >> div;
			if (NumTries > 0 && num > 0 && div > 0) {
			srand(time(0));
			for (int tries = 0; tries < NumTries; tries++) {
				int a = rand() % num + 1;
				int b = rand() % div + 1;
				if (b == a) {
					wins++;
				}
				else
					cout << "RWP = " << float(wins) / (tries + 1) << '\n';
			}
	}
		else cout << "Invalid Syntax!\n";
	
}



Hello porkshop,

After your else statement put std::cout << "\n The number of times is: " << numTries - 1 << std::endl;.

If you mean something else rephrase your question.

Andy

P.S. Watch your indenting. From line 11 everything is in to far.
Last edited on
Topic archived. No new replies allowed.