I'm writing a program and am getting both an LNK2005 and LNK1169 error. I might be doing something wrong with trying to call the various files as this is the first program Ive tried writing with more than one. I was given a .h file to begin with that I cant change:
#ifndef CIRCLE
#define CIRCLE
using namespace std;
class Circle
{
Circle();
~Circle(){}
vector<string> getNames();
vector<string> playGame(int n, int m);
int reportSafeIndex(int n, int m);
};
#endif
Then I wrote the following:
#include "CIRCLE.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class Circle
{
public:
string getNames();
string playGame(int m, int n);
int reportSafeIndex (int n, int m);
private:
string name[20];
int n;
int m;
};
string Circle :: getNames ()
{
string list;
//initialize the 20 names
name [0]="Alice";
name [1]="Brent";
name [2]="Carly";
name [3]="Dan";
name [4]="Emily";
name [5]="Fred";
name [6]="George";
name [7]="Henry";
name [8]="Isabel";
name [9]="Josephus";
name [10]="Katie";
name [11]="Lauren";
name [12]="Matt";
name [13]="Nicole";
name [14]="Olivia";
name [15]="Pam";
name [16]="Quinten";
name [17]="Ron";
name [18]="Silvia";
name [19]="Tim";
//Output the names given
int i;
for (i=0; i<20; i++)
{
list = list + " " + name[i];
}
cout << list;
return list;
}
// Begins playing the game, running through the people
string Circle :: playGame(int m, int n)
{
int i;
string name;
string die;
while (n < 10 || n > 20)
{
cout << "How many people (10-20) would you like to play with?" << endl;
cin >> n;
}
while (m < 1)
{
cout << "How many people would you like to skip each time?" << endl;
cin >> m;
}
for (i=0; i<n; i++)
{
die = name[(i*m)%n];
}
cout << die;
return die;
}
// Reports where the user should stand to be the last person remaining, returns -1 if outside perameters.
int Circle :: reportSafeIndex (int n, int m)
{
int i;
int safe;
cout << "How many people (10-20) would you like to play with?" << endl;
cin >> n;
cout << "How many people would you like to skip each time?" << endl;
cin >> m;
if (n < 10 || n > 20 || m < 1)
{
return -1;
}
else
{
for (i=0; i<n; i++)
{
safe=((i*m)%n+1);
}
cout << safe;
return safe;
}
}
And lastly I wrote a main:
#include "CIRCLE.h"
#include <iostream>
#include <string>
#include "Josephus.cpp"
using namespace std;
int main()
{ int m; int n;
Circle game1;
game1.getNames();
game1.playGame(m, n);
game1.reportSafeIndex(n, m);
}
I beleive the problem is in the second file.
If anyone can help me it would be greatly appreciated. Thanks