I am new to c++ and am writing a simple role playing mining game. I have only been coding for a couple weeks, but I've encountered an error that I've been working on for several days and have still come up with nothing. I've even considered just scrapping my program and trying it again. I have 4 files: Game.cpp, header.h, nuggetsFound.cpp, and days.cpp. I'm trying to have a global variable that I can change throughout files, however, even though I haven't even been redefining or anything, I continue to encounter this crazy error that says "float percentOfOres" (?percentOfOres@@3MA) already defined in Days.obj. Several of these pop up for all my variables and files, and I'm going insane. I'm only 13, so I can't always get all of the help I need, so I would really appreciate it if you guys can help me. Thanks! (I excluded nuggetsFound.cpp because it's basically the same situation as days.cpp. There's also a lot more code in game.cpp but I just included what I thought was relevant. These are the two files
game.cpp
#include <iostream>
#include <string>
#include <stdlib.h>
#include <windows.h>
#include <cstdlib>
#include <ctime>
#include "Header.h"
using namespace std;
float netWorth{ 0.0 };
float salary{ 0.0 };
float percentOfOres{ 0.0 };
int main()
{
cout << "Welcome to Miner Man!\n";
cout << "Press any key and press enter to continue";days.cpp
#include "game.cpp"
using namespace std;
void days()
{
for (int iii{ 1 }; iii <= 5; iii++)
{
cout << "Net Worth: " << netWorth << "\tSalary: " << salary <<
"\tPercent of Ores: " << percentOfOres;
cout << "\n";
cout << "CCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n";
cout << "CCCCCCCCCCCCC\n";
cout << "CCCCCCCC\n";
cout << "CCCC ///////\n";
cout << "CCC |O O |\n";
cout << "CC | __ |\n";
cout << "C asssssssa\n";
cout << "C a sssssss a\n";
cout << "C a sssssss a\n";
cout << " a sssssss a\n";
cout << "C h sssssss a\n";
cout << "C p h sssssss \n";
cout << "C p h l l\n";
cout << "CC p h p l l\n";
cout << "CCC p p p p___l l___\n";
cout << "CCCCC L___l l___l\n";
cout << "CCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n";
Sleep(500);
system("cls");
cout << "Net Worth: " << netWorth << "\tSalary: " << salary <<
"\tPercent of Ores: " << percentOfOres;
cout << "\n";
cout << "CCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n";
cout << "CCCCCCCCCCCCC\n";
cout << "CCCCCCCC\n";
cout << "CCCC p ///////\n";
cout << "CCC p |O O |\n";
cout << "CC p | __ |\n";
cout << "C phhhhhhaaaa sssssssa\n";
cout << "C p sssssss a\n";
cout << "C p sssssss a\n";
cout << "C p sssssss a\n";
cout << "C sssssss a\n";
cout << "C sssssss \n";
cout << "C l l\n";
cout << "CC l l\n";
cout << "CCC ___l l___\n";
cout << "CCCCC L___l l___l\n";
cout << "CCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n";
Sleep(500);
system("cls");
}
}
#pragma once
#include <iostream>
#include <string>
#include <stdlib.h>
#include <windows.h>
#include <cstdlib>
#include <ctime>
#include "data.hpp"
using namespace std;
void days();
void endOfDayNugs();
void endOfDayNugs()
{
srand((unsigned)time(0));
int silverFoundToday = rand() % 25;
srand((unsigned)time(0));
int goldFoundToday = rand() % 10;
srand((unsigned)time(0));
int diamondsFoundToday = rand() % 5;
if (silverFoundToday == 0)
{
cout << "Sorry, you found no Silver today\n";
Sleep(3000);
system("cls");
}
else if (silverFoundToday > 0)
{
for (int sss{ 1 }; sss < 3; sss++)
{
cout << "You found " << silverFoundToday << " silver!\n";
cout << "\n/SSSSSS\\\n";
Sleep(500);
system("cls");
}
if (percentOfOres == 0)
{
cout << "You don't make any money of your silver yet, but continue working towards that promotion!";
Sleep(5000);
system("cls");
}
else if (percentOfOres > 0)
{
cout << "You made " << percentOfOres * silverFoundToday << "dollers off of your silver\n";
netWorth += percentOfOres * silverFoundToday;
Sleep(5000);
system("cls");
}
}
if (goldFoundToday == 0)
{
cout << "Sorry, you found no gold today\n";
Sleep(3000);
system("cls");
}
else if (goldFoundToday > 0)
{
for (int ggg{ 1 }; ggg < 3; ggg++)
{
cout << "You found " << goldFoundToday << " gold!\n";
cout << "\n/GGGGGG\\\n";
Sleep(500);
system("cls");
}
if (percentOfOres == 0)
{
cout << "You don't make any money of your gold yet, but continue working towards that promotion!";
Sleep(5000);
system("cls");
}
else if (percentOfOres > 0)
{
cout << "You made " << percentOfOres * goldFoundToday << "dollers off of your gold\n";
netWorth += percentOfOres * goldFoundToday;
Sleep(5000);
system("cls");
}
}
if (diamondsFoundToday == 0)
{
cout << "Sorry, you found no diamonds today\n";
Sleep(3000);
system("cls");
}
else if (diamondsFoundToday > 0)
{
for (int ddd{ 1 }; ddd < 3; ddd++)
{
cout << "You found " << diamondsFoundToday << " diamonds!\n";
cout << "\n/DDDDDD\\\n";
Sleep(500);
system("cls");
}
if (percentOfOres == 0)
{
cout << "You don't make any money of your diamonds yet, but continue working towards that promotion!";
Sleep(5000);
system("cls");
}
else if (percentOfOres > 0)
{
cout << "You made " << percentOfOres * diamondsFoundToday << "dollers off of your diamonds\n";
netWorth += percentOfOres * diamondsFoundToday;
Sleep(5000);
system("cls");
}
}
}