Minute by Minute output

Hello there,

I have been working on a code that needs to determine the number of ants that will destroy a stadium from a text file.

1
2
3
4
5
6
7
8
9
10
11
12
Ants--Yards per minute
20000    1
100000   25
90000    25
80000    25
50000    1
60000    1
60000    10
60000    20
0        1
100000   10
100000   5


When the ants are released, the band can stomp 10,000 ants per minute and after 5 minutes they will only be able to stomp 5,000 per minute

A person also has a spray can and if the ants get past the 50 yard mark, he will spray it and kill 50,000 ants.

The goal of the program is to display the results minute by minute. The ants destroy at a certain speed (yards per minute) and I need to display how much they have destroyed. So essentially 4 columns with that data with the 4th column displaying how many ants were stomped per minute.

I have a few questions,

1. How can I get it so that it displays my results every minute in the cout part?

2. My output seems to keep going past the 11 scenarios, how do I stop it from doing so?





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
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
	const int
		notTired = 10000,
		areTired = 5000,
		doSpray = 50000;
		

	int
		linecount = 0,
		Ants = 0,
        yardsPerMin = 0,
		yardsAte = 0,
		minsElapsed = 0,
		Field = 100,
		antsStomped = 0;

        ifstream inFile;
        inFile.open ("antsData.txt");

		if (!inFile)
		{
			cout << "The file is not open." << endl;
			return(-1);
		}
		
		inFile >> Ants;
        inFile >> yardsPerMin;
        while (inFile)
        {
			linecount++;

			cout << setw(44) << "Scenario " << linecount << setw (53) << endl;
			cout << "--------------------------------------------------------------------------------"<< endl;
			cout << setw(20) << "Time Elapsed" << setw(28) << "Yards Devoured" << setw(28) << "Surviving Ants" << setw(25) <<
			"    --------------------------------------------------------------------------------"<< endl;
			cout << setw(14) << minsElapsed << setw(26) << yardsAte << setw(32) << Ants << endl;
			
		
			

			do
			{
				
				Ants = (Ants - notTired);
				yardsAte = (minsElapsed * yardsPerMin);
				antsStomped = (notTired * minsElapsed);
				Field = Field - yardsAte;
				}
			while (yardsAte < 50 && Ants != 0 && minsElapsed <= 5);
					
				do
				{
					
					
					Ants = (Ants - areTired);
					yardsAte = (minsElapsed * yardsPerMin);
					antsStomped = (antsStomped + (areTired * (minsElapsed - 5)));
					Field = Field - yardsAte;
				}
				while (yardsAte < 50 && Ants != 0 && minsElapsed > 5);

			
					do
					{
						
						Ants = (Ants - areTired - doSpray);
						yardsAte = (minsElapsed * yardsPerMin);
						antsStomped = (antsStomped + (areTired * minsElapsed));
						Field = Field - yardsAte;
					}
					while (yardsAte >= 50 && Ants != 0);

			system("pause");

			Ants = 0;
			yardsPerMin = 0;
			
        }
        inFile.clear ();
        inFile.close ();
        return (0);
}


so for instance the second output should look like so:
1
2
3
4
5
6
7
8
9
10
11
Time Elapsed   Stadium Devoured    Surviving Ants
   in min.          in yds.
=============================================================================
    0                 0                100000
    1                25                 90000        Band stomps 10000 ants.
    2                50                 30000        Band stomps 10000 ants.
                                                     Prof kills 50000 ants with
                                                     spray.
    3                75                 20000        Band stomps 10000 ants.
    4               100                 10000        Band stomps 10000 ants.
=============================================================================


I have tried doing this code many which ways and still cant seem to figure it out. Any help would be appreciated!
You could create a simple timer. Note. It doesn't have to be a struct.

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

struct timer
{
	double startTime;
	double currentTime;
};

int main()
{
	timer update;
	double updateNow = 5000; // 5 seconds

	int exitCondition = 0;

	update.startTime = GetTickCount(); // Get the current system time as the start time

	while( true )
	{
		update.currentTime = GetTickCount() - update.startTime; // update the current time each loop

		if( update.currentTime > updateNow )
		{
			std::cout << "You've just updated your info to the screen.\n";
			std::cout << "Ants, blah, stomped etc.\n";

			++exitCondition; // Increment. Just so we can exit the infinite loop

			update.startTime = GetTickCount(); // reset the start time, so you can count back up to 'updateNow'
		}

		if( exitCondition >= 5 )
			break;
	}
	
	return 0;
}
Topic archived. No new replies allowed.