problem with function

example of problem:: 5+5 = 10 and then the user used other operate 5 - 2 = 3 the program will print out
the total of 5 -2 = 3 and the sum is 13 my problem is that the functions can't return the value TOTAL.. Sorry but my characters are limit i can reply if that helps you!!! Thank you !!!
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#include <iostream>
#include<iostream>
#include<string>
#include<iomanip>
#include<stdio.h>                    
#include <cmath>                      
#include <pthread.h>
#include <unistd.h>

using namespace std;

void quit()              
{  

	char option2;
	double val = 5.9;   

	cout << "Are you sure you want to quit from the program??(Y/N): "<<endl;
    cin >> option2;    

	if ((option2=='Y') || (option2=='y'))   
	{ 
cout << "GoodBye!!! C ya later!!!.. "<<endl; 
}
	else 
		if ((option2=='N') || (option2=='n')) 
		{ 
			cout <<"You will now return to main menu!!!"<<endl;  
	   		}
		else 
			if ((option2!='y') || (option2!='Y') || (option2!='n') || (option2!='N'))
				cout << "Error input.. The program will exit in 5 seconds..."<<endl; 
			    sleep ( val );                                                
} 

double addition()   
{  
	double num1,num2;
    double total;

    cout << "Addition"<<endl;
	cout << "********"<<endl; 
	cout << "Enter 2 numbers to calculate: "<<endl;
    cin >> num1>>num2;
   
   total = num1 + num2;  
   total += total;   

   cout <<"The total sum of "<<num1<<" + "<<num2<<" = ";  
   return (total); 
}  

double subtraction()   
{  
	double num1,num2;    
	double total;

	cout <<"Subtraction"<<endl;
	cout <<"***********"<<endl;
	cout <<"Enter 2 number to calculate: "<<endl;
	cin >> num1>>num2;    

	total = num1 - num2;    
    total +=total;

    cout <<"The subtraction of "<<num1<<' - '<<num2<<" = "; 
    return (total);  

} 

double multiplication()  
{ 

double num1,num2;
double total;     

    cout <<"Multiplication"<<endl;
	cout <<"***********"<<endl;   
	cout <<"Enter 2 number to calculate: "<<endl;
	cin >> num1>>num2;    

	total = num1 * num2;  
    total += total;    
	cout << "The total multiplication of "<<num1<<" * "<<num2<<" = ";  
	return (total);  
}  

double division()  
{  

	double num1,num2;
	double total;      

	    cout <<"Division"<<endl;
		cout <<"***********"<<endl;    
		cout <<"Enter 2 number to calculate: "<<endl;
		cin >> num1>>num2;   

		total = num1 / num2;  
		total += total;  

		cout << "The total division of "<<num1<<" / "<<num2<<" = "; 
        return (total); 
}  

double sum_squared()   
{  
	double num1,num2;            
	double total = 0.0;
	double displayedVal;
	displayedVal = 0.0;


	    cout <<"Sum squared"<<endl;  
		cout <<"***********"<<endl;
		cout <<"Enter 2 number to calculate: "<<endl;
		cin >> num1>>num2;  

		displayedVal =  pow (num1, num2);  
		cout << "The total sum  squared of "<<num1<<" ^ "<<num2<<" is ";  
        total += displayedVal;  

		return (total);  
}  

double less_than_relation() 
{ 

	    double num1,num2;   
		double total;

		    cout <<"Less than relation"<<endl;  
			cout <<"***********"<<endl;
			cout <<"Enter 2 number to calculate: "<<endl;
			cin >> num1>>num2;   

			if (num1<num2)  
			{   
		    total = num2;  
			return (total);
			cout <<"The "<<num1<<" is smaller (<) than "<<num2<<endl;
			} 
			else 
		cout << "The first number "<<num1<<"is not smaller than num2"<<endl;  
			total = num1;  
			return (total); 
}

double greater_than_relation()  
{  

	        double num1,num2;
			double total;     

			    cout <<"Greater than relation"<<endl; 
				cout <<"***********"<<endl;
				cout <<"Enter 2 number to calculate: "<<endl;
				cin >> num1>>num2;  

				if (num1>num2)  
				{  
			    total = num1; 
				cout <<"The "<<num1<<" is greater than (>) "<<num2<<endl;   
				return (total);
				} 
				else 
				total = num2;  
			    cout << "The first number "<<num1<<"is not greater than the second number "<<num2<<endl; 
				return (total); 

}  // end bracket of function



void quit2()   // function of the second quit
{  // start bracket of the function

	quit();  //called the 1st function of the quit..


}  // end bracket of the function quit2
void calculator()   // function of the calculator

{ //start bracket of the function
	char opt;  // variables of calculation function

	cout <<"********Welcome To Calculator********"<<endl;              //welcome screen of the void function......
	cout <<"*************************************"<<endl;              //****************************************
	cout <<"Please chose an operator you want to used: "<<endl;
	cout <<"+: Addition" <<endl;
	cout <<"-: Subtraction" <<endl;
	cout <<"*: multiplication"<<endl;
	cout <<"/: division"<<endl;                                        //All the operators options that user has available to used....
	cout <<"^: sum squared"<<endl;
	cout <<"<: less than relation"<<endl;
	cout <<">: greater than relation"<<endl;
	cout <<"c: clear sum"<< endl;
	cout <<"q: quit"<< endl;
	cin >>opt;                     //reads the opt input from the user

switch (opt)  //switch statement for the previous option that user enter
{   // start bracket of the switch statement
case '+':   // case 1 for addition
	addition();   //called the function addition...
    break;  //break of the case addition

case '-':    // case 2 for subtraction
	subtraction();  // called the subtraction function....
	break; // break of the case subtraction

case '*':   // case 3 for multiplication
	multiplication();  // called the multiplication function...
	break;  // break of the case multiplication

case '/':   // case 4 for division
	division(); // called the division function...
	break; // break of the case division

case '^':  // case 5 for sum squared...
	sum_squared();  // called the sum_squared function
	break; // break of the case sum squared

case '<':  // case 6 for the less_than_relation function
	less_than_relation();  // called the less_than_relation function
	break; // break of the case less than relation

case '>':  // case 7 for the greater_than_relation function
	greater_than_relation(); // called the greater_than_relation function
	break; // break of the case greater than relation

case 'c':  // case 8 for the clear function

	 // Nothing until know since  the TOTAL SUM isn't works
	break;  // break of the case clear

case 'q':  // case 9 for the quit
	quit2();  // called the quit2 function
	break; // break of the case quit2

}//end bracket of the switch case



}// end bracket of the calculator function

int main(double total) // int main of the program include the total retrun
{   // start bracket of int main


char option1;
double val = 5.9;   // all the variable of the int main

cout <<"********Welcome To Calculator********"<<endl;
cout <<"*************************************"<<endl;
cout <<"Please choose one of the following: ";
cout <<endl;
cout <<"1. Calculator "<<endl;
cout <<"2. Quit "<<endl;
cin >>  option1;          

while ((option1 == '1') || (option1=='2')) 
	{   // start bracket of while loop
	if (option1 == '1')   // if statement of the option1
	{  // start bracket of if statement
	calculator();   // called the calculator function if the option1 is 1
	cout <<total<<endl;  // print out the results of the two numbers


	} // end bracket of if statement
	else   // else of if statement

	if (option1 == '2')  // if statement of option1 check if the user choose the second option
	{ //start bracket of if statement
		quit();  // called the function of quit...
        break; // break of the while loop to stop the while
	} // end of if statement
	else // else of if statement
		if ((option1!='1') || (option1!='2')) // if statement... check if the input of user is not 1 or 2
		{ // start bracket of if statement
		cout <<"Error Input... The program will exit in 5 seconds...."<<endl; // prints out an error message if the user add a wrong input
		sleep ( val );  // sleep the program in 5 seconds
		break;  // break the program of while loop
		}//bracket for if statement
	}//bracket for while loop

	return 0;  // return to 0
} //bracket for int main 
Last edited on
total += total; // save the value and keep ¿what?
ne555 thats for forum... just search and you will find it I can't found it now... But I am pretty sure that I copy from this forum
Topic archived. No new replies allowed.