i have a program with a while loop and i want to time the program to see time differences under different parameters
i just looked and realized that i dident save the code (oops but its 5 in the morn so i have an excuse) i will post it when i get it back up
it is not a long program code wise
but it checks numbers against collatz's theory so it can run a very long time
p.s. i just wanted you guys to know that i recently took a class that was supposed to cover the basics of C++ but the instructor was not that great but the tutorial on this website saved my rear
int main ()
{
int f,i,c;
cout << "Enter the starting number > ";
cin >> i;
cout << "Enter the ending number > ";
cin >> f;
----------__________----------__________----------__________----------__________----------
while (i>1 && i<f) {
c=i;
while (c>1){
if (c%2!=0)
c+=1;
else
c/=2;
}
cout<<i<<" , "<<c<<endl;
if (c!=1)
cout<<c<<" , "<<i<<endl;
else
++i;
}
----------__________----------__________----------__________----------__________----------
cout << "All numbers worked. \n\n ";
system("pause");
return 0;
}
i don't know how to make this look nice like so any others have done but this is the code
---___--- lines are where i would like the timer to start and stop
if you know how to put the code in the little box that would also help
thanks
time() calculates the number of seconds since January 1, 1970.
Use it at the beginning of the program once, and at the end of it once again.
Then subtract the former from the latter.
1 2 3 4 5 6 7 8 9 10 11 12
#include <stdio.h>
#include <time.h>
int main ()
{
time_t seconds;
seconds = time (NULL);
printf ("%ld hours since January 1, 1970", seconds/3600);
return 0;
}