Compile Error

I'm trying to compile my program to make check if I coded everything to do as it should, but I get Build Failed every time and I do not know why. Could someone help me figure out why it won't compile?

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <cstdlib>
#include <iostream>
#include <stack>
#include <string>
using namespace std;

void Infix()
{
    int math1;
    int math2;
    string math3;
    int math4;
    cout << "Please enter a number.";
    cin >> math1;
    cout << "Please enter an operator.";
    cout << "The options are + - * /";
    cin >> math3;
    cout << "Please enter a number.";
    cin >> math2;
    cout << "You entered: " << math1 << math3 << math2;
    if(math3 == "+")
    {
        math4 = math1 + math2;
    }else{
        if(math3 == "-")
        {
            math4 = math1 - math2;
        }else{
            if(math3 == "*")
            {
                math4 = math1 * math2;
            }else{
                if(math3 == "/")
                {
                    math4 = math1 / math2;
                }
            }
        }
    }
    cout << math1 << " " << math3 << " " << math2 << " = " << math4;
}

void Prefix()
{
    int math1;
    int math2;
    string math3;
    int math4;
    cout << "Please enter an operator.";
    cout << "The options are + - * /";
    cin >> math3;
    cout << "Please enter a number.";
    cin >> math1;
    cout << "Please enter a number.";
    cin >> math2;
    cout << "You entered: " << math3 << math1 << math2;
    if(math3 == "+")
    {
        math4 = math1 + math2;
    }else{
        if(math3 == "-")
        {
            math4 = math1 - math2;
        }else{
            if(math3 == "*")
            {
                math4 = math1 * math2;
            }else{
                if(math3 == "/")
                {
                    math4 = math1 / math2;
                }
            }
        }
    }
    cout << math3 << " " << math1 << " " << math2 << " = " << math4;
}

void Postfix()
{
    int math1;
    int math2;
    string math3;
    int math4;
    cout << "Please enter a number.";
    cin >> math1;
    cout << "Please enter a number.";
    cin >> math2;
    cout << "Please enter an operator.";
    cout << "The options are + - * /";
    cin >> math3;
    cout << "You entered: " << math1 << math2 << math3;
    if(math3 == "+")
    {
        math4 = math1 + math2;
    }else{
        if(math3 == "-")
        {
            math4 = math1 - math2;
        }else{
            if(math3 == "*")
            {
                math4 = math1 * math2;
            }else{
                if(math3 == "/")
                {
                    math4 = math1 / math2;
                }
            }
        }
    }
    cout << math1 << " " << math2 << " " << math3 << " = " << math4;
}

int main() 
{
    stack<int> choice;
    int choice1;
    string yes;
    bool again = true;
    do
    {
        choice.push(0);
        cout << "Welcome to this Math Program!";
        cout << "Would you like to use:";
        cout << "1. infix";
        cout << "2. prefix";
        cout << "3. postfix";
        cout << "4. exit";
        cout << "Please type in the number corresponding to your choice.";
        cin >> choice1;
        cout << "Are you sure you would like to choose this menu option?";
        cout << "y or n";
        cin >> yes;
        if(yes == "n")
        {
            cout << "Please choose your desired menu option.";
            cin >> choice1;
        }
        while(choice1<1 || choice1>4)
        {
            cout << "Please enter a valid choice ";
            cin >> choice1;
       }
        while(choice.top() = choice1)
        {
            choice.pop();
            cout << "Please choose a different menu option";
            cout << "Reason: You just used this menu option a few seconds ago.";
            cin >> choice1;
        }
        switch (choice1)
        {
            case 1:
                choice.push(choice1);
                Infix();
                again = true;
                break;
            case 2:
                choice.push(choice1);
                Prefix();
                again = true;
               break;
            case 3:
                choice.push(choice1);
                Postfix();
                again = true;
               break;
            case 4:
                cout << "Exiting program...";
                again = false;
                break;
        } 
    }while(again);
}


Also, here is what shows up when I try to compile, if anyone wants to see it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
cd 'C:\Users\Mouse\Documents\NetBeansProjects\Mod1InPrePost'
C:\cygwin64\bin\make.exe -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/c/Users/Mouse/Documents/NetBeansProjects/Mod1InPrePost'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin-Windows/mod1inprepost.exe
make[2]: Entering directory '/cygdrive/c/Users/Mouse/Documents/NetBeansProjects/Mod1InPrePost'
mkdir -p build/Debug/Cygwin-Windows
rm -f "build/Debug/Cygwin-Windows/main.o.d"
g++    -c -g -MMD -MP -MF "build/Debug/Cygwin-Windows/main.o.d" -o build/Debug/Cygwin-Windows/main.o main.cpp
mkdir -p dist/Debug/Cygwin-Windows
g++     -o dist/Debug/Cygwin-Windows/mod1inprepost build/Debug/Cygwin-Windows/Stacks.o build/Debug/Cygwin-Windows/main.o 
build/Debug/Cygwin-Windows/main.o: In function `main':
/cygdrive/c/Users/Mouse/Documents/NetBeansProjects/Mod1InPrePost/main.cpp:116: multiple definition of `main'
build/Debug/Cygwin-Windows/Stacks.o:/cygdrive/c/Users/Mouse/Documents/NetBeansProjects/Mod1InPrePost/Stacks.cpp:21: first defined here
collect2: error: ld returned 1 exit status
make[2]: *** [nbproject/Makefile-Debug.mk:64: dist/Debug/Cygwin-Windows/mod1inprepost.exe] Error 1
make[2]: Leaving directory '/cygdrive/c/Users/Mouse/Documents/NetBeansProjects/Mod1InPrePost'
make[1]: *** [nbproject/Makefile-Debug.mk:60: .build-conf] Error 2
make[1]: Leaving directory '/cygdrive/c/Users/Mouse/Documents/NetBeansProjects/Mod1InPrePost'
make: *** [nbproject/Makefile-impl.mk:40: .build-impl] Error 2

BUILD FAILED (exit value 2, total time: 27s)
closed account (48T7M4Gy)
It doesn’t solve your problem but your program compiles and runs on the shell here. That’s by pressing the gear wheel at the top right of your code text box.

On line 13 of the error message the error indication is you have two files in the project which have a main() If that’s the case then you will need to remove one, but not delete it.
/cygdrive/c/Users/Mouse/Documents/NetBeansProjects/Mod1InPrePost/main.cpp:116: multiple definition of `main'
build/Debug/Cygwin-Windows/Stacks.o:/cygdrive/c/Users/Mouse/Documents/NetBeansProjects/Mod1InPrePost/Stacks.cpp:21: first defined here

You probably haven't made a separate "project" for this assignment.
Last edited on
That helped me figure out the problem, thank you! It runs on NetBeans now :)
Topic archived. No new replies allowed.