I have here the the cpp file named as clock

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

#include <cstdlib>
int main() {
// ofstream constructor opens file
ofstream outClientFile("clients.dat", ios::out);
if(!outClientFile) {
cerr << "File could not be opened" << endl;
exit(1);
}
cout << "Enter the account, name, and balance.\n"
<< "Enter end-of-file to end input.\n? ";
int account;
string name;
double balance;
while(cin >> account >> name >> balance) {
outClientFile << account << ' ' << name
<< ' ' << balance << '\n';
cout << "? ";
}

return 0; // ofstream destructor closes file

}

and the name as timefetch.cpp

#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
#include <cstdlib>

using namespace std;
int main() {
// ofstream constructor opens file
ofstream outClientFile("bible13.txt", ios::out);
if(!outClientFile) {
cerr << "File could not be opened" << endl;
exit(1);
}
clock_t start = clock();
for (int i = 0; i<50000; i+=5000)
{
	cout<< i << endl;
}
clock_t end = clock();
double runningTime = (double) (end - start) / (double) CLOCKS_PER_SEC;
cout<<"The running Time is"<<runningTime;
system ("pause");
return 0;
}

the result are 2 errors naming:

Error 1 error LNK2005: _main already defined in Fetch.obj Clock.obj
Error 2 fatal error LNK1169: one or more multiply defined symbols found C:\Documents and Settings\Aldrich Uy\My Documents\Visual Studio 2005\Projects\clock sort\Debug\clock sort.exe 1


what should I do pls. help me

you can't have the same function name in two or more *.cpp files and link them together.

>>what should I do pls.
Name one of the functions something else.

you can't have the same function name in two or more *.cpp files and link them together.

>>what should I do pls.
Name one of the functions something else.

well what i do know is transfer the contents of the main of clock.cpp to timefetch.cpp

and here is the code:

#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
#include <cstdlib>

using namespace std;
int main() {
// ofstream constructor opens file
ofstream outClientFile("bible13.txt", ios::out);
if(!outClientFile) {
cerr << "File could not be opened" << endl;
exit(1);
}
clock_t start = clock();

for (int i = 1;  i<=5000; i++)
{
	
	cout<< i << endl;
	
}
clock_t end = clock();
double runningTime = (double) (end - start) / (double) CLOCKS_PER_SEC;
cout<<"The running Time is"<<runningTime;

system ("pause");


cout << "Enter the account, name, and balance.\n"
<< "Enter end-of-file to end input.\n? ";
int account;
string name;
double balance;
while(cin >> account >> name >> balance) {
outClientFile << account << ' ' << name
<< ' ' << balance << '\n';
cout << "? ";
}
return 0;
}

but i still have problem with this....
the timefetch.cpp result is counting the running time from 0 to 50 thousand although the result is there correctly posted... i want to post it this way...
for every count of 5000 there the result is posted and I don't want to see other numbers to posted and show the result except ( 5000, 10000, 15000, 20000, 25000, 30000, 35000, 40000, 45000 & 50000)
for example the result must show:
5000
the running time is 1.09
10000
the running time is 2.012
.
.
.
50000
the running time is 9.026

can you do something about it?

can you do something about it?

Well, you could do something about it... In your for loop, do something like:

if (i%5000 == 0)
{
     end = clock();
     runningTime = (double) (end - start) / (double) CLOCKS_PER_SEC;

     cout << i << endl << "the running time is " << runningTime << endl;
}

Well, you could do something about it... In your for loop, do something like:

if (i%5000 == 0)
{
     end = clock();
     runningTime = (double) (end - start) / (double) CLOCKS_PER_SEC;

     cout << i << endl << "the running time is " << runningTime << endl;
}

you place it inside the for loop?

Yes but you will need to change around some declarations (I.e. end and runningTime need to be declared before the loop). Also, I just copied your code from outside the loop because you said it was working, so if you move it inside the loop, you no longer need it outside...

Note: I haven't tested any of your code or my own...I don't have a compiler on this computer. Should be ok though...gl

Yes but you will need to change around some declarations (I.e. end and runningTime need to be declared before the loop). Also, I just copied your code from outside the loop because you said it was working, so if you move it inside the loop, you no longer need it outside...

Note: I haven't tested any of your code or my own...I don't have a compiler on this computer. Should be ok though...gl

According to my understanding... runningTime must be declared as double but I don't know what to declare for end in the end=clock();
because I think this could clash due to redifinition

and yet when I put the clock_t as declaration before the word end the result of time is not increasing and yet they are all the same.... what I mean is every reach of range of 5000 the result is posted....

lol dont redefine stuff. I said move the declarations around. To before where you use it. Before the loop. You already have the working code (I assume since that is what you said in a previous post). So move the declaration of end and running time before the loop, then just use the variables within the conditional statement as I provided...

lol dont redefine stuff. I said move the declarations around. To before where you use it. Before the loop. You already have the working code (I assume since that is what you said in a previous post). So move the declaration of end and running time before the loop, then just use the variables within the conditional statement as I provided...

Hey pal I've figured out that the last parts are almost the same.... is it because of the speed of time allotted?

This article has been dead for over six months. Start a new discussion instead.