# new to coding

 simeon landers · May 23, 2015 can anyone tell ,e what i did wrong with this code the number always comes out wrong#include using namespace std;int subtract() ;int multiply()  ;int divide() ;int add() ;int main(){int x ;cout << "please read below: \n For Addition enter 1 \n For subtraction enter 2 \n For Multiplication enter 3 \n For division enter 4" << endl ;    cin >> x ;    if(x==1){         add() ;    }        if(x==2){            subtract() ;        }            if(x==3){                 multiply() ;            }                if(x==4){                    divide() ;                }    return 0 ;}int add() {    int a ;    int b ;    int sum ;    sum = a + b ;    cout << "pick your first number \n" ;    cin >> a ;    cout << "pick your second number \n" ;    cin >> b ;    cout << sum ;     return 0;}int subtract(){int a ;int b ;int sum ;sum = a - b ;cout << "pick a number please \n" ;cin >> a ;cout << "pick another number please \n" ;cin >> b ;cout << sum ;return 0;}int multiply() {int a ;int b ;int sum ;sum = a * b ;cout << "pick a number \n" ;cin >> a ;cout << "pick a number \n " ;cin >> b ;cout << sum ;}int divide() {int a ;int b ;int sum ;sum = a / b ;    cout << "pick a number \n" ;    cin >> a ;    cout << "pick a number \n" ;    cin >> b ;    cout <<  sum ;    cout << " Remainder" << a % b << endl ;    return 0 ;

## Replies

 Silard Kovac · May 23, 2015 at the functions divide() etc. dont use int divide() ... use void divide()int is for numbersvoid is for function Eyeshield Rosalin · May 23, 2015 // Here is my algo for thisint divide() {int a ;int b ;int sum ;// you declared the sum here already but the user has not entered anything yetsum = a / b ;cout << "pick a number \n" ;cin >> a ;cout << "pick a number \n" ;cin >> b ;//if you cut that line of code above and paste it here, maybe it should worksum = a / b ;cout << sum ;cout << " Remainder" << a % b << endl ;return 0 ; Silard Kovac · May 23, 2015 Oh yea... we can use int myFunc(void) when we dont need anything on returnvoid myFunc(int) when we want a return.. sorry my mistake. Adrian S · May 23, 2015 You did the operation sum/substract/etc. with unknown values, not the one you got from the user. Do the addition/etc. with the input values - after getting them from user.
• 1

## C++

129,864 followers