Functions.

i have written a program which adds and subtracts with functions (copied out of the book)the addition works. However when i call the subtraction function,it doesn't takeaway, it only adds.
//
//
//
#include<iostream.h>
#include<math.h>
using namespace std;
//functions.
//addition
double adding(int x,int y){
int b=y+x;
cout<<"="<<b<<endl;
return b;
};
//subtraction
double sub_traction(int a,int c){
int h=a-c;
cout<<"="<<h<<endl;
return h;
};
//program
int main (){
int sum;
int sum1;
cin>>sum>>sum1;
sub_traction(sum,sum1);
}
Let me fix this....
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream.h>
#include<math.h>
//functions.
//addition
double adding(int x,int y){
int b=y+x;
cout<<"="<<b<<endl;
return b;
}
//subtraction
double subtraction(int a,int c){
int h=a-c;
cout<<"="<<h<<endl;
return h;
}
//program
int main (){
int sum;
int sum1;
cin>>sum>>sum1;
subtraction(sum,sum1);
}



i think i fixed it

im not sure
Last edited on
closed account (zb0S216C)
Program Programmer wrote:
1
2
#include<iostream.h>
#include<math.h> 

C headers, not C++.

Program Programmer wrote:
 
return b;

Truncation. Why return "double" if the decimal is removed?

Program Programmer wrote:
 
return h;

Truncation. Same as above.

Program Programmer wrote:
 
int main ()

...doesn't return anything.

Wazzak
Last edited on
Topic archived. No new replies allowed.