problems with a tip calculator.

I'm having problems getting this program to build. (sorry for all the 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

#include <iostream>
#include "calc.h"
#include "percentFunctions.h"

using namespace std;

void fivePercent();
void fifteenPercent();
void twentyPercent();

int main()
{
	double bill;
	
	cout<<"******************************************************\n";
	cout<<"            WELCOME TO THE C++ TIP CALCULATOR!        \n";
	cout<<"              written in C++ by John McCrary          \n";
	cout<<"******************************************************\n";
	cout<<"\n";
	cout<<"Please input the cost of your bill: ";
	cin>>bill;
	cout<<"\n";
	cout<<"Please choose which percent to tip.\n";
	cout<<"\n";
	cout<<"1) 5 percent"<<endl;
	cout<<"2) 15 percent"<<endl;
	cout<<"3) 20 percent"<<endl;
	int choice;
	cin>>choice;
	
	switch(choice)
	{
		case 1:
		fivePercent();
		break;
		
		case 2:
		fifteenPercent();
		break;
		
		case 3:
		twentyPercent();
		break;
		
		default:
		cout<<"Terminating program";
		break;
	}
	
	return 0;
}


and i think there is something wrong with my percentFunctions.h

here is the 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

#ifndef ADD_H
#define ADD_H

void fivePercent()
{
	double Xbill;
	double percent_of_bill;
	double taxedBill;
	
	Xbill = bill;
	
	cout<<"You have chosen to tip 5 percent!\n";
	cout<<"\n";
	percent_of_bill = 'Xbill * (5/100)';
	'percent_of_bill + Xbill' = taxedBill;
	cout<<"\n";
	cout<<"Your total bill will be "<<taxedBill<<" dollars.";
}

void fifteenPercent()
{
	double Xbill;
	double percent_of_bill;
	double taxedBill;
	
	Xbill = bill;
	
	cout<<"You have chosen to tip 5 percent!\n";
	cout<<"\n";
	percent_of_bill = 'Xbill * (15/100)';
	'percent_of_bill + Xbill' = taxedBill;
	cout<<"\n";
	cout<<"Your total bill will be "<<taxedBill<<" dollars.";
}

void twentyPercent()
{
	double Xbill;
	double percent_of_bill;
	double taxedBill;
	
	Xbill = bill;
	
	cout<<"You have chosen to tip 5 percent!\n";
	cout<<"\n";
	percent_of_bill = 'Xbill * (1/5)';
	'percent_of_bill + Xbill' = taxedBill;
	cout<<"\n";
	cout<<"Your total bill will be "<<taxedBill<<" dollars.";
}

#endif 


I don't know if you will be able to just look at the code and see what is wrong with it. but my compiler (g++) says:
1
2
3
4
5
6
7
g++ -Wall -o "mainTipCalc" "mainTipCalc.cxx" (in directory: /home/john/Desktop/programming/tip calculator)
/tmp/ccsYopWy.o: In function `main':
mainTipCalc.cxx:(.text+0x2b7): undefined reference to `fivePercent()'
mainTipCalc.cxx:(.text+0x2be): undefined reference to `fifteenPercent()'
mainTipCalc.cxx:(.text+0x2c5): undefined reference to `twentyPercent()'
collect2: ld returned 1 exit status
Compilation failed.


it compiles fine but when i try to build the program, it says
 
compilation failed!!!!!!!
There are a load of errors in percentFunctions.h, misspells, extra quotation marks, invalid assignments etc. The error you are getting is that the linker can't find definitions for the percentage functions, I don't know why that is tbh, when i fixed the errors in percentFunctions.h it linked fine for me (I just removed the #include for calc.h, doesn't seem to be used here). The other problem with the code is that the functions in percentFunctions.h don't have access to the variables defined in mainTipCalc.cxx. So when you refer to 'bill' in those functions, the compiler won't know what you are talking about. I would suggest adding a parameter to each function so you can pass the bill value as an argument when you call each function. Hope that helps a bit.
thanks man i'll try to fix up the header lol
Topic archived. No new replies allowed.