### 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.

 ``123456789101112`` ``````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?

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687`` ``````#include #include #include 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:
 ``1234567891011`` ``````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.

 ``1234567891011121314151617181920212223242526272829303132333435363738`` ``````#include #include 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.