Calculator program

Hey guys, I cannot figure out how to fix this to where it works. I am supposed to get 2 numbers then have the person choose what they want to do to the numbers. 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
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
176
177
178
//Mike Karbowiak
//12/24/13
//Mathematics
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
void hello();
float menu();
float Add(float num1, float num2);
float Subtract(float num1, float num2);
float Multiply(float num1, float num2);
float Divide(float num1, float num2);
void Output(float total1);

int goodbye();

int main(){
	
	system ("Color C");

	float num1;
	float num2;


	hello();

	cout<< "Hello, today we are going to deal with some mathematics.\n\n";

	cout<< "Please enter two numbers. (hit enter after you input the first number)\n\n";

	cin>>num1;
	cin>>num2;

	float total = menu();


	system("cls");

	Output(total);

	goodbye();

	return(0);
}


void hello()
{
	system("Color C");

	cout<<"\t\t\t*******************************\n";
	cout<<"\t\t\t*                             *\n";
	cout<<"\t\t\t*   Hello, my name is Mike    *\n";
	cout<<"\t\t\t*                             *\n";
	cout<<"\t\t\t*    I am Lord and Master     *\n";
	cout<<"\t\t\t*                             *\n";
	cout<<"\t\t\t*******************************\n" <<endl;
}


float menu() { //displays the food and drink items available

	int answer;

	float total = 0;

	cout<< "What would you like to do?" << "\n\n";

	cout<< "Please input the number that corresponds with your choice." << "\n\n";

	cout<< "\t\t\t Food \n" <<endl;

	cout<< "[1] Add" << '\t' << "[2] Subtract" << "\n\n";

	cout<< "[3] Multiply" << '\t' << "[4] Divide" << "\n\n";

	cin>>answer;

	switch(answer)
	{

	case 1:
		total = Add();
		Output(total);
		//output_case = 1;
		break;

	case 2:
		total = Subtract();
		//output_case = 2;
		break;

	case 3:
		total = Multiply();
		//output_case = 3;
		break;

	case 4:
		total = Divide();
		//output_case = 4;
		break;
	}

	return (total);
}

float Add(float num1, float num2) {
	
	//float num1;
	//float num2;
	float sum=0;
	float num = 0;

	sum = num1 + num2;
	return(sum);
}

float Subtract(float num1, float num2) {

	//float num1;
	//float num2;
	float diff=0;
	float num = 0;

	diff = num2 - num1;
}

float Multiply(float num1, float num2) {

	//float num1;
	//float num2;
	float product=0;
	float num = 0;

	product = num1 * num2;
}

float Divide(float num1, float num2) {

	//float num1;
	//float num2;
	float quotient=0;
	float num = 0;

	quotient = num2 / num1;
}

void Output(float total) {

	float answer=total;
	
	cout<<"\nYou're answer is " << answer << endl;

	system ("pause");
	system ("cls");
}

int goodbye(){

	//system("cls");

	int again = 1;	//local variables

	cout<<"Do you want to run again? ";
	cout<<"Enter 1 for yes, 0 for no \n";
	cin>>again;

	if(again==1)
		main();
	if(again==0)
		return (0);
}



The errors I am getting so far are:

error C2660: 'Add' : function does not take 0 arguments
error C2660: 'Subtract' : function does not take 0 arguments
error C2660: 'Multiply' : function does not take 0 arguments
error C2660: 'Divide' : function does not take 0 arguments

Please help, thanks!
You're missing the return statements to some of your functions.

On lines 83-106, what do you expect to happen? The compiler will not turn into a human and say "I suppose he wants to ask the user for two values, pass those two values to each of these function calls, and then tell the user about the returned values".

Also, what is line 154 for? There's no reason to do that.
Last edited on
the return function under the switch should return that variable (total), shouldn't it?

EDIT I'm trying different suggestions and trying to make them work.
Last edited on
Also, don't ever call the main function - it's special. Instead set up a loop in main that depends on the return value from the goodbye function.

And everyone seems to forget for division by zero.

return is not a function - it's a statement - no need for the parentheses.

Have fun!!
Topic archived. No new replies allowed.