-1

the error is : 1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol WinMain@16 referenced in function __tmainCRTStartup and it's give me this error too fatal error LNK1120: 1 unresolved externals

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct student
{
    string name;
string department;
double first;
double second;
};
class CS112Section
{
student stu[30];
int numOfStudent;
public:
CS112Section();
~CS112Section();
void printSection();
void insert(student student);
int getNumOfStudent();
string MaxFirstAndSecond();
void Average(double&, double&);
bool isFull();
bool isEmpty();
void AddBounsFirst(int);
};
void main()
{
CS112Section section;
char choice;
bool finish = true;
while (finish != false)
{
    cout << "1-Insert Info From .Txt file.\n2-Insert Student     Manually.\n3-Show The Number Of Student In The Class.\n";
    cout << "4-Print The Content Of The Section.\n5-The Student With The Full Marks First And Second.\n6-Show If";
    cout << " The Class Full Or Not.\n7-Print The Average Of The First And The Second.\n8-Do You Want To Add Bouns ?\n";
    cout << "9-Exit.";
    cin >> choice;
    switch (choice)
    {
    case 1:
    case 2:
    case 3:
        cout << "The Number Of Student In The Section : " << section.getNumOfStudent();
    case 4:
        section.printSection();
    case 5:
        section.MaxFirstAndSecond();
    case 6:
        if (section.isEmpty() == 1)
            cout << "The Class Is Empty\n";
        else if (section.isFull() == 1)
            cout << "The Class Is Full";
    case 7:
        double avF, avS;
        section.Average(avF, avS);
        cout << "The Average Of The First Is : " << avF;
        cout << "\nThe Average Of The Section Is : " << avS << endl;
    case 8:
        int x;
        cout << "How Many Marks Do You Want To Add ?";
        cin >> x;
        section.AddBounsFirst(x);
    case 9:
        finish = false;
    }
}
}
CS112Section::CS112Section(){ numOfStudent = 0; }
CS112Section::~CS112Section(){ cout << "Good Luck In Your Final ^_^"; }
void CS112Section::printSection()
{
cout << "the Number Of Student In The Section is : "<<numOfStudent;
cout << "---------------------------------------------";
cout << "Name\tFirst\tSecond\tDepartment\n";
for (int i = 0; i < 30; i++)
    cout << stu[i].name << "\t" << stu[i].first << "\t" << stu[i].second << "\t"<<stu[i].department << "\n";
}
void CS112Section::insert(student student)
{
for (int i = 0; i < 30;i++)
if (stu[i].name.empty() == 1 && stu[i].first == stu[i].department.npos&&stu[i].second == stu[i].department.npos&&stu[i].department.empty() == 1)
    stu[i] = student;
}
int CS112Section::getNumOfStudent()
{
return numOfStudent;
}
string CS112Section::MaxFirstAndSecond()
{
for (int i = 0; i < 30; i++)
if (stu[i].first == 30 && stu[i].second == 30)
    return stu[i].name;
}
void CS112Section::Average(double&avF, double&avS)
{
double sumF = 0, sumS = 0;
for (int i = 0; i < 30; i++)
    {
        sumF += stu[i].first;
        sumS += stu[i].second;
    }
for (int i = 0; i < 30; i++)
{

    if (stu[i].first == stu[i].department.npos)
        sumF = 0;
    if (stu[i].second == stu[i].department.npos)
        sumS = 0;
}
avF = sumF / 30;
avS = sumS / 30;
}
bool CS112Section::isFull()
{
if (numOfStudent == 30)
    return 1;
return 0;
}
bool CS112Section::isEmpty()
{
if (numOfStudent == 0)
    return 1;
return 0;
}
void CS112Section::AddBounsFirst(int Bouns)
{
for (int i = 0; i < 30; i++)
    stu[i].first += 1;
}
  • 1
    possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Lightness Races in Orbit Mar 31 '14 at 18:03
  • 1
    Please search before posting. – Lightness Races in Orbit Mar 31 '14 at 18:03
  • @LightnessRacesinOrbit I think this question is a little more specific than that generic one. – Mark Ransom Mar 31 '14 at 18:06
  • @MarkRansom I've added up an answer there covering this point recently ... (Feel free to improve it, f you don't think it matches the OP's case) – πάντα ῥεῖ Mar 31 '14 at 18:40
  • @πάνταῥεῖ that link has a lot of good information in it, sorry I missed it. In this case though the compiler is clearly Microsoft's rather than gcc. – Mark Ransom Mar 31 '14 at 19:36
  • @MarkRansom _'sorry I missed it'_ De nada! Since it's at the very end of the answers list, it's likely to be missed. I didn't mention GCC consciously there, just the term _IDE_. In fact the OP's problem is based on IDE specific creation of a particular kind of project (Windows App -> Console App) as you correctly stated in your answer. – πάντα ῥεῖ Mar 31 '14 at 19:46

1 Answers1

3

In this case it looks like you've used Visual Studio to create a Windows application where you intended to create a Console application instead. See WinMain entry point - WinMain is used instead of main for Windows projects.

To fix it you'll need to recreate your project, choosing the proper type.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622