Help with a Covid survey for class

Write your question here.
I am writing a code for my advanced c++ class and I believe I have done everything correctly but keep getting the LNK2019 error. I have searched for how to fix it but the more I look it up the more I get confused. Im not to sure if its something with the code thats causing this or if its what I am using, I am currently running Visual Studio 2019 through Amazon AppStream (VMWare).

Put the code you need help with here.
Here is what I have so far...

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

class NODE
{
public:
NODE();
void read_stats();
void count_stats();
void calc_stats();
void print_stats();

private:
struct list_node
{
string gender;
int age;
int count = 0;
string answer1;
string answer2;
string answer3;
string answer4;

list_node* next;
};
list_node* first, * prev, * current;
char add;
int total = 0;
int male = 0, female = 0, mvac = 0, fvac = 0, u21 = 0, g21 = 0, uvac = 0, gvac = 0, mask = 0, vac = 0, trust = 0, ntrust = 0;
double mper = 0.0, fper = 0.0, mvacper = 0.0, fvacper = 0.0, uvacper = 0.0, gvacper = 0.0, trustper = 0.0, maskper = 0.0, vacper = 0.0, u21per = 0.0, g21vac = 0.0;
};
void NODE::count_stats()
{
current = first->next;
while (current != NULL)
{
total = total + current->count;

current = current->next;
if (current->gender == "male") {
male++;
if (current->answer1 == "yes")
mvac++;
}
else if (current->gender == "female") {
female++;
if (current->answer1 == "yes")
fvac++;
}
if (current->age < 21) {
u21++;
if (current->answer1 == "yes")
uvac++;
}
else {
g21++;
if (current->answer1 == "yes")
gvac++;
}
if (current->answer2 == "yes")
trust++;
else
ntrust++;
if (current->answer3 == "yes")
mask++;
if (current->answer4 == "yes")
vac++;
};
}

void NODE::calc_stats()
{
fper = female * 100 / total;
mper = male * 100 / total;
fvacper = fvac * 100 / female;
mvacper = mvac * 100 / male;
u21per = uvac * 100 / u21;
g21vac = gvac * 100 / g21;
trustper = trust * 100 / total;
maskper = mask * 100 / total;
vacper = vac * 100 / total;
}
void NODE::print_stats()
{
current = first->next;
while (current != 0)
{
cout << "\nGender: " << current->gender << "\nAge: " << current->age <<
"\nDid they get the vaccine? " << current->answer1 <<
"\nDo they trust the vaccine? " << current->answer2 <<
"\nDo they think requiring masks should continue? " << current->answer3 <<
"\nDo they think that the vaccine should be required? " << current->answer4 <<

"\n-------------------------------------------------------------\n";

current = current->next;
}
cout << "number of people surveyed: " << total << endl;
cout << "number of females: " << female << endl;
cout << "number of males: " << male << endl;
cout << "number of females who got the vaccine: " << fvac << endl;
cout << "number of males who got the vaccine: " << mvac << endl;
cout << "number of people under 21: " << u21 << endl;
cout << "number of people under 21 who got the vaccine: " << uvac << endl;
cout << "number of people 21 or older: " << g21 << endl;
cout << "number of people 21 or older who got the vaccine: " << gvac << endl;
cout << "number of people who trust the vaccine: " << trust << endl;
cout << "number of people who do not trust the vaccine: " << ntrust << endl;
cout << "number of people who think masks should be required: " << mask << endl;
cout << "number of people who think the vaccine should be required: " << vac << endl;
cout << "percent of females: " << fper << endl;
cout << "percent of males: " << mper << endl;
cout << "percent of females getting the vaccine: " << fvacper << endl;
cout << "percent of males getting the vaccine: " << mvacper << endl;
cout << "percent of people under 21 who got the vaccine: " << uvacper << endl;
cout << "percent of people older than 21 who got the vaccine: " << gvacper << endl;
cout << "percent of people who trust the shot: " << trustper << endl;
cout << "percent of people who think masks should be required: " << maskper << endl;
cout << "percent of people who think vaccine should be required: " << vacper << endl;
}


The error I am receiving is LNK2019- unresolved external symbol_main referenced in function "int_cdecl invoke_main(void)" (?, invoke_main@@YAHXZ)... MSVCRTD.lib(exe_main.obj) line 1
Last edited on
keep getting the LNK2019 error

If you believe we've memorised every VS numerical error code, you're very much mistaken. If you're getting an error message, then show us the complete error message.
Where's your
int main()
function?
The error I am receiving is LNK2019- unresolved external symbol_main referenced in function "int_cdecl invoke_main(void)" (?, invoke_main@@YAHXZ)... MSVCRTD.lib(exe_main.obj) line 1
You need an
int main()
function.
I added this function in:
int main()
{
NODE value;
value.read_stats();
value.count_stats();
value.calc_stats();
value.print_stats();

system("pause");
return 0;
}

I am still receiving the same error
Always trying cleaning and rebuilding, first.

Check project configuration. Linker->System->SubSystem should be Windows. [1]

If you use CMake you have to set WIN32 flag in add_executable
add_executable(${name} WIN32 ${source_files})
See CMake Doc [https://cmake.org/cmake/help/v3.8/command/add_executable.html] for more information. [2]

[1] https://stackoverflow.com/a/46085227
[2] https://stackoverflow.com/a/43633504
Last edited on
I tried all of these steps as well and I am still receiving the same error.

What else should I try?

Start from scratch, make a new project that is just:

1
2
3
4
5
6
#include <iostream>

int main()
{
    std::cout << "Hello\n";
}


Build that, see if it successfully builds. If so, then copy your old code into this new project.
The sample successfully built but when I put my code back in I still receive the same error
Then all I can say is to slowly, gradually put your stuff back in, such that you can see a point A where it works, and a point B where it doesn't work, and then post the exact code for both instances. (Source control and file diffing help a lot here.)
Last edited on
#include <iostream>
#include <string>
using namespace std;

class NODE
{
public:
NODE();
void read_stats();
void count_stats();
void calc_stats();
void print_stats();

private:
struct list_node
{
string gender;
int age;
int count = 0;
string answer1;
string answer2;
string answer3;
string answer4;

list_node* next;
};

list_node* first, * prev, * current;
char add;
};
int main()
{
NODE value;
value.read_stats();
value.count_stats();
value.calc_stats();
value.print_stats();

system("pause");
return 0;
}

int total = 0;
int male = 0, female = 0, mvac = 0, fvac = 0, u21 = 0, g21 = 0, uvac = 0, gvac = 0, mask = 0, vac = 0, trust = 0, ntrust = 0;
double mper = 0.0, fper = 0.0, mvacper = 0.0, fvacper = 0.0, uvacper = 0.0, gvacper = 0.0, trustper = 0.0, maskper = 0.0, vacper = 0.0, u21per = 0.0, g21vac = 0.0;

};

void NODE::count_stats()
{
current = first->next;
while (current != NULL)
{
total = total + current->count;

current = current->next;
if (current->gender == "male") {
male++;
if (current->answer1 == "yes")
mvac++;
}
else if (current->gender == "female") {
female++;
if (current->answer1 == "yes")
fvac++;
}
if (current->age < 21) {
u21++;
if (current->answer1 == "yes")
uvac++;
}
else {
g21++;
if (current->answer1 == "yes")
gvac++;
}
if (current->answer2 == "yes")
trust++;
else
ntrust++;
if (current->answer3 == "yes")
mask++;
if (current->answer4 == "yes")
vac++;
};
}

void NODE::calc_stats()
{
fper = female * 100 / total;
mper = male * 100 / total;
fvacper = fvac * 100 / female;
mvacper = mvac * 100 / male;
u21per = uvac * 100 / u21;
g21vac = gvac * 100 / g21;
trustper = trust * 100 / total;
maskper = mask * 100 / total;
vacper = vac * 100 / total;
}
void NODE::print_stats()
{
current = first->next;
while (current != 0)
{
cout << "\nGender: " << current->gender << "\nAge: " << current->age <<
"\nDid they get the vaccine? " << current->answer1 <<
"\nDo they trust the vaccine? " << current->answer2 <<
"\nDo they think requiring masks should continue? " << current->answer3 <<
"\nDo they think that the vaccine should be required? " << current->answer4 <<

"\n-------------------------------------------------------------\n";

current = current->next;
}
cout << "number of people surveyed: " << total << endl;
cout << "number of females: " << female << endl;
cout << "number of males: " << male << endl;
cout << "number of females who got the vaccine: " << fvac << endl;
cout << "number of males who got the vaccine: " << mvac << endl;
cout << "number of people under 21: " << u21 << endl;
cout << "number of people under 21 who got the vaccine: " << uvac << endl;
cout << "number of people 21 or older: " << g21 << endl;
cout << "number of people 21 or older who got the vaccine: " << gvac << endl;
cout << "number of people who trust the vaccine: " << trust << endl;
cout << "number of people who do not trust the vaccine: " << ntrust << endl;
cout << "number of people who think masks should be required: " << mask << endl;
cout << "number of people who think the vaccine should be required: " << vac << endl;
cout << "percent of females: " << fper << endl;
cout << "percent of males: " << mper << endl;
cout << "percent of females getting the vaccine: " << fvacper << endl;
cout << "percent of males getting the vaccine: " << mvacper << endl;
cout << "percent of people under 21 who got the vaccine: " << uvacper << endl;
cout << "percent of people older than 21 who got the vaccine: " << gvacper << endl;
cout << "percent of people who trust the shot: " << trustper << endl;
cout << "percent of people who think masks should be required: " << maskper << endl;
cout << "percent of people who think vaccine should be required: " << vacper << endl;
}



I have fixed the initial errors, but 3 new ones popped up on the same line.
E0169 says expected a declaration
C2059 says syntax error: ‘}’
C2143 says syntax error: missing ‘;’ before ‘}’,

It is on the bolded line
Use code formatting. Edit your post and add [code] and [/code] around your code.

If you follow proper indentation, errors like that are much less likely: Around line 41 is the end of main. The code you have after that is not part of main, and the }; at the end (~line 47) is not matched with anything.
Last edited on
Topic archived. No new replies allowed.