hello guys and hope you are fine :)
please take a look to this code
#include <iostream>
using namespace std;
int sum(int num1,int num2, int sum1){
cout <<"Please enter two numbers:";
cin >> num1 >> num2;
sum1 = num1 + num2;
cout << sum1;
return 0;
}
int div(int num3,int num4, int sum2){
cout <<"Please enter two numbers:";
cin >> num3 >> num4;
sum2 = num3 / num4;
cout << sum2;
return 0;
}
int main()
{
char q ='y'; // to quite the programme
int choose,num1,num2,num3,num4,sum1,sum2;
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){
sum(num1,num2,sum1);
}else if(choose == 2){
div(num3,num4,sum2);
}
cout <<" ,Repeat?";
cin >> q;
}
return 0;
}
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
so my question now can i use the same name of each varible in each function?
this is an example,the num1,num2,sum1 are vaibles in the function'sum' but i want to be the same name in the div function?
second qustion, why i must declare the varibles of my functions in the main function again?
and is there any way to avoid declaring the varibles in the main function?
last question , can anybody show me the diffrernt in calling by value or refrence in my code?
waiting for you