What is wrong with this?

Im trying to compile this, however I don't understand what the problem is.

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
#include <iostream>
#include <Windows.h>
#include <string>
#include "functions.h"
using namespace std;

void cls();

int main()
{
	double x;
	double y;
	char answer;
	
	HANDLE hConsole;

	hConsole = GetStdHandle (STD_OUTPUT_HANDLE);

	
	bool run = true;

	while (run){
		SetConsoleTextAttribute
		(hConsole, FOREGROUND_RED | FOREGROUND_INTENSITY);

		cout <<"Welcome to my thingy I made, choose one of the following choices." << endl;
		cout <<"1 - Calculator" << endl;
		cout <<"q - Quit" << endl;

		cin >> answer;
		

		switch(answer){
			
			case '1':
				while(run){
					
					cal();

	}
		}

	}

	return 0;
}

void cls(){

	cout << string(50, '\n');
		
}


functions.h
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
#include <iostream>
using namespace std;

int cal(){
	double num1;
	double num2;
	char choice2;

	bool run = true;

	while(run){
	cout <<"Choose an option." <<endl;
	cout <<"1.Addition" <<endl;
	cout <<"2.Subtraction" <<endl;
	cout <<"3.Multiplication" <<endl;
	cout <<"4.Division" <<endl;
	cout <<"5.Square root" <<endl;
	cout <<"6.Raise to the power" <<endl;
	cout <<"7.Round up the value" <<endl;
	cout <<"8.Round down the value" <<endl;
	cout <<"9.Press 'q' to quit." <<endl;
	
	cin >> choice2;

	}

	return choice2;
}
closed account (zb0S216C)
Errors? Warnings? Unexpected output? You need to be more specific than My code doesn't work. What's wrong with it? Pardon the reply, but it's kinda frustrating when vital details aren't provided.

So, I'll ask nicely of you. Can you describe what the issue is?

Wazzak
Last edited on
Yeah, sure, this is the output:

1
2
3

main.obj : error LNK2005: "int __cdecl cal(void)" (?cal@@YAHXZ) already defined in functions.obj
C:\Users\Dario\Desktop\Projects\Project1\Debug\Project1.exe : fatal error LNK1169: one or more multiply defined symbols found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
closed account (zb0S216C)
It's telling you that cal( )'s body has been defined on numerous occasions. I've spotted functions.obj, which could only mean that functions.h has an associated source module. Could you post that source module?

Note that header modules should only contain constants, declarations and prototypes (with the exception of templates).

Wazzak
Last edited on
I noticed you have bool run = true; in both your header and in your main (). That could explain the "...already defined in functions.obj".
@JakeIsBoss:
No it wouldn't. Firstly, as Framework pointed out, the error is referring to cal(), secondly, bool run = true is defined in the main () function and the cal () function, so there will, again be no error of the kind
Topic archived. No new replies allowed.