Calculator code build error

I am writing a calculator menu code with outputs, but I am constantly getting the following error when trying to build:
https://i.imgur.com/0BzhOHb.png

how do I resolve this?
here's my code:

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
  // Calc.cpp : Defines the entry point for the application.
//

#include "Calc.h"
#include "stdafx.h"
#include <iostream>
#include <cctype>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
using namespace std;
char menu1();
int addition(int a, int b);
void substraction(int a, int b);
int multiplication(int a, int b);
double circle(int a);
int triangle(int a, int b);
int square(int a);
void evenodd(int q);


//Calcualtor Menu
char menu1()
{
	char choice = 'Z';
	while ((choice > 'O') || (choice < 'A'))

	{
		cout << "Enter O to quit\n";
		cout << "Enter A for Addition\n";
		cout << "Enter B for Area of a Circle\n";
		cout << "Enter C for Area of a Right triangle \n";
		cout << "Enter D for Area of a Square \n";
		cout << "Enter E for Covnert decimal to bases 2 - 16 \n";
		cout << "Enter F for Exponent of 2 integers \n";
		cout << "Enter G for Get Factorial \n";
		cout << "Enter H for Even/odd \n";
		cout << "Enter I for Integer Division \n";
		cout << "Enter J for Get real division of 2 integers \n";
		cout << "Enter K for Multiplication \n";
		cout << "Enter L for Quotient of 2 numbers \n";
		cout << "Enter M for Remainder if 2 integers \n";
		cout << "Enter N for Substraction \n";
		cin >> choice;
		choice = toupper(choice);					//Convert to non-case-sensitive
	}
	return choice;

}

//Calculator Menu Printout

int _tmain(int argc, _TCHAR* argv[])
{
	int choice, i1, i2;
	char s1[4], s2[4];
	choice = menu1();
	if (choice == 'Q')
		return 0;
	cout << "Enter number x: ";
	cin >> s1;
	i1 = atoi(s1);
	if ((choice != 'G') && (choice != 'H') && (choice != 'B') && (choice != 'D'))
	{
		cout << "Enter number y: ";
		cin >> s2;
	}
	i2 = atoi(s2);
	if (choice == 'A')
		cout << addition(i1, i2) << endl;
	else if (choice == 'O')
		substraction(i1, i2);
	else if (choice == 'H')
		evenodd(i1);
	if (choice == 'L')
		cout << multiplication(i1, i2) << endl;
	else if (choice == 'B')
		cout << "Area of circle: " << circle(i1) << endl;
	if (choice == 'C')
		cout << "Area of a Right triangle: " << triangle(i1, i2) << endl;
	else if (choice == 'D')
		cout << "Area of square: " << square(i1) << endl;;

}

//Addition: Choice 'A'

int addition(int a, int b)
{
	return(a + b);
}

//Area of a circle: Choice 'B'
double circle(int a)
{
	return (3.14*a*a);
}

//Area of a right triangle: Choice 'C'
int triangle(int a, int b)
{
	return(((a*b) / 2));
}


//Area of a square: Choice 'D'
int square(int a)
{
	return(a * a);

}

//Convert decimal to bases 2 - 16: Choice 'E'



//Even/Odd: Choice 'H'
void evenodd(int q)
{
	if (q % 2 == 0)
		cout << "Number " << q << " is even\n";
	else cout << "Number " << q << " is odd\n";
}

// Multiplication: Choice 'L'
int multiplication(int a, int b)
{
	return(a*b);
}

//Substraction: Choice 'O'
void substraction(int a, int b)
{
	cout << a << " - " << b << " = " << a - b << endl;
}



Thanks!!!
Hello vacisneros,

Your error comes from using "_tmain". This may be OK for a different type of program, but for a Win 32 Console Application it will not work. What it is looking for is just int main () .

For your include files:
1
2
3
4
5
6
7
#include "Calc.h"
#include "stdafx.h"
#include <iostream>
#include <cctype>
#include <stdio.h>
#include <cstdio>
#include <cstdlib> 


Sometimes it does not make any difference what order these includes are in and other times it does.

I would suggest:
1
2
3
4
5
6
7
8
#include "stdafx.h"  // <--- Best to leave out when posting here. VS likes to see this file first.
#include <iostream>
#include <cctype>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>

#include "Calc.h" 


I have not looked closely at your code, but the last three include files should not be needed for a C++ program. "iostream" should cover all that you need. "cctype" i the best file to use, but I m not sure if it is needed.

You should start learning not to use using namespace std; as it WILL be a problem in the future.

I will look the program over more and see if I find anything else,

Hope that helps,

Andy
Thanks Andy!

I also found that it's also a part of Linker problems in VS 2017.

What I did was:
Change Properties -> Linker -> System -> SubSystem (in Visual Studio).

from Windows (/SUBSYSTEM:WINDOWS) to Console (/SUBSYSTEM:CONSOLE)
Hello vacisneros,

It may not seem important to you, but I can not compiler run the program with out the "Calc.h" file. It would also help to know what is in that file to see if anything is wrong.

Andy
Hello vacisneros,

I am not familiar with the 2017 version nor with what you have described. Not sure if the changes you made will work or not.

What might have happened is that you created the wrong type of project from the start. In which case it would be easier to just start over and create a new project. then you can copy the code from the old project. Easier than spending hours trying to change what you have and not knowing what you are doing.

Hope that helps,

Andy
Topic archived. No new replies allowed.