question in functions

hello everyone

i'm trying to use fuunvtions in ly simple programe

this code is very simple, it's just ask a user to choose which programme he want whther to find the sum of two numbers or to find the Division

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
#include <iostream>
using namespace std;
int sum(int num1,int num2){
    int sum;
	sum = num1 + num2;
	return sum;
	}
int div(int num1,int num2){
    int sum;
	sum = num1 / num2;
	return sum;
	}
int main()
{
char q ='y'; // to quite the programme
int choose;
while(q == 'y'){
  cout <<"Welcome to the super programme"<<endl;
  cout <<"1- finding the sum of the numbers."<<endl;
  cout <<"2- finding the divide of the numbers."<<endl;
  cout <<"please choose which programe you want:"<<endl;
  cin >> choose;
  while(choose < 1 || choose > 2){
  cout<<"please choose ethir '1' or '2'";
  cin >> choose;
  }
  if(choose == 1){
  cout <<"Please enter two numbers:";
  cin >> num1 >> num2;
  sum(num1,num2);
  }else if(choose == 2){
  cout <<"Please enter two numbers:";
  cin >> num1 >> num2;
  div(num1,num2);
  }
  cout <<" ,Repeat?";
  cin >> q;
  }
    return 0;
}


can you show me my problem here?

waiting for you
Now it works.
Compare the two codes to find diferences.


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
#include <iostream>
using namespace std;

int sum(int num1,int num2){
    int sum;
    sum = num1 + num2;
    return sum;
}
	
int divider(int num1,int num2){
    int sum;
	sum = num1 / num2;
	return sum;
}

int main() {
    char q ='y'; // to quite the programme
    int choose;
    while(q == 'y'){
        cout <<"Welcome to the super programme"<<endl;
        cout <<"1- finding the sum of the numbers."<<endl;
        cout <<"2- finding the divide of the numbers."<<endl;
        cout <<"please choose which programe you want:"<<endl;
        cin >> choose;
        while(choose < 1 || choose > 2){
            cout<<"please choose ethir '1' or '2'";
            cin >> choose;
        }
        if(choose == 1){
            int num1, num2, total;
            cout <<"Please enter a number numbers:";
            cin >> num1;
            cout <<"Please enter another number:";
            cin >> num2;
            total = sum(num1,num2);
            cout << "The result is " << total << endl;
        }else if(choose == 2){
            int num1, num2, total;
            cout <<"Please enter a number numbers:";
            cin >> num1;
            cout <<"Please enter another number:";
            cin >> num2;
            total = divider(num1,num2);
            cout << "The result is " << total << endl;
        }
        cout <<" ,Repeat?";
        cin >> q;
    }
    return 0;
}

thanks brazyuri86 (3)

so i must to Separate cin>>?

one more question, can i avoid doing this total = sum(num1,num2); ad just do like this sum(num1,num2);

thank again :)
No, because it returns an int, and if you were to just call it, it would have nothing to return to, causing an error. :D
OK i see

thanks :)
Topic archived. No new replies allowed.