help with program

Hi. I am trying to write a program that asks the user to guess how long it will take for the computer to count to 1 million, then counts to one million and shows then how long it really took. The code I have written so far successfully counts to 1 million and displays it, but i dont know how to implement the time logging aspect. Thank you

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

using namespace std;


int main()
{
    int response, counter;

    cout<<"Would you like to see your computer count to 1,000,000? If yes, enter a 1, if not enter a 0. Then press enter. " <<endl;
    cin>>response;
    counter=0;

    if(response==1)
    {
        cout<<"Ok. This will be fun. How long do you think it will take? Enter in seconds and remember your computer can count pretty fast. "<<endl;
        while(counter<=1000000)
        {
            cout<<counter<<endl;
            counter++;
        }
    }
    else
    cout<<"Okay. Maybe some other time. "<<endl;

    return 0;
}

#include <iostream>
#include <cstdlib>
#include <time.h>

using namespace std;

int main()
{
int response=0, counter=0;
clock_t tStart = clock();

/* Do your stuff here */
while(counter<=1000000)
{
cout<<counter<<endl;
counter++;
}

printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
return 0;
}
Last edited on
Thank you:D
needed #include <stdio.h> too and then it worked. Thanks
Topic archived. No new replies allowed.