Can't figure it out.

I only want the number of cannibals to decrease if the number of missionaries decrease by a whole number. Ex.30 missionaries, 10 cannibals. 29 Missionaries, 9 cannibals. 28.1 missionaries, 9 cannibals. 28 Missionaries, 8 cannibals. I've tried everything I can think of and I can figure out how to program it to do so. Any suggestions?

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
  #include<iostream>
#include<cmath>

using namespace std;

int main()
{
	int TarzanDistance = 80;
	int numCannibals = 10;
	double numMissionaries = 30;
	double EatingRate = 0.1;
	double hold;
	double TempHold;
	double Hold_ANS = 0;
	
	int Time = 0;
	int NightStarts = 3;
	int NightEnds = 12;
	
	int NightSpeed = 4;
	int DaySpeed = 7;

	cout << "END OF HOUR\tMISSIONARIES LEFT\tCANNIBALS EATING\tTARZAN DISTANCE"
		 << endl << endl;
	cout << Time << "\t\t" << numMissionaries << "\t\t\t"
		 << numCannibals << "\t\t\t" << TarzanDistance << endl << endl;
	
	do {
		Time++;
		Time = Time % 24; //to makre sure it doesn't pass 24 hours
		hold = numMissionaries;
		numMissionaries = numMissionaries - numCannibals*EatingRate;
		TempHold = hold - numMissionaries;
		Hold_ANS + TempHold;

		if (Hold_ANS / 1 == 1)//checks if a full missionary was consumed
		{
			Hold_ANS = fmod(TempHold,1);
			numCannibals--;
		}
		
		//update tarzan's distance
		if (Time > NightStarts && Time <= NightEnds)
			TarzanDistance = TarzanDistance - NightSpeed;
		else
			TarzanDistance = TarzanDistance - DaySpeed;
		
		if (TarzanDistance <= 0)
			break;

		//print results
		cout << Time << "\t\t" << numMissionaries << "\t\t\t"
		     << numCannibals << "\t\t\t" << TarzanDistance << endl << endl;

		
	} while (TarzanDistance != 0);
	


	
}
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
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
	int TarzanDistance = 80;
	int numCannibals = 10;
	double numMissionaries = 30;
        int numFullMissionaries=30;
	double EatingRate = 0.1;
	
	int Time = 0;
	int NightStarts = 3;
	int NightEnds = 12;
	
	int NightSpeed = 4;
	int DaySpeed = 7;

	cout << "END OF HOUR\tMISSIONARIES LEFT\tCANNIBALS EATING\tTARZAN DISTANCE"
		 << endl << endl;
	cout << Time << "\t\t" << numMissionaries << "\t\t\t"
		 << numCannibals << "\t\t\t" << TarzanDistance << endl << endl;
	
	do {
		Time++;
		Time = Time % 24; //to makre sure it doesn't pass 24 hours
		numMissionaries = numMissionaries - numCannibals*EatingRate;

		if (numMissionaries<=numFullMissionaries-1)//checks if a full missionary was consumed
		{
			numCannibals--;numFullMissionaries--;
		}
		
		//update tarzan's distance
		if (Time > NightStarts && Time <= NightEnds)
			TarzanDistance = TarzanDistance - NightSpeed;
		else
			TarzanDistance = TarzanDistance - DaySpeed;
		
		if (TarzanDistance <= 0)
			break;

		//print results
		cout << Time << "\t\t" << numMissionaries << "\t\t\t"
		     << numCannibals << "\t\t\t" << TarzanDistance << endl << endl;

		
	} while (TarzanDistance != 0);
	


	
}
awesome.

but i don't understand how this worked.

1
2
3
4
if (numMissionaries<=numFullMissionaries-1)//checks if a full missionary was consumed
		{
			numCannibals--;numFullMissionaries--;
		}
Let's suppose that at some point numFullMissionaries=25. If numMissionaries is 24.3 you still have 0.3 missionaries left before you decrease the number of cannibals. If numMissionaries is 23.8, it means that you already eat one complete missionary, so numFullMissionaries=24 and you decrease the number of cannibals
I get it know, thank you so much.
Topic archived. No new replies allowed.