Hello,
I can't figure out why this code isn't working as I think it should do.
I want to load variables to the heap while displaying the percentage loaded.
Here is my code:
#include <iostream>
usingnamespace std;
#define MAX_VARIABLES 100
int main() {
int* pointers[MAX_VARIABLES + 1];
cout << "Press any key to start loading resources" << endl;
cin.get();
for (int i = 1; i <= MAX_VARIABLES; i++) {
pointers[i] = newint;
cout << (i/MAX_VARIABLES)*100 << "% completed" << endl;
}
cout << "Press any key to unload them..." << endl;
cin.get();
for (int i = 1; i <= MAX_VARIABLES; i++) {
delete pointers[i];
cout << (i/MAX_VARIABLES)*100 << "% completed" << endl;
}
cout << "Press any key to exit..." << endl;
cin.get();
return 0;
}
The problem is in the loop while the cpu is calculating the percentage,
I get the following output:
0% completed
0% completed
0% completed
0% completed
0% completed
0% completed
(...)
100% completed