+ 1

Can you guys help me out ? The result of sum is 0 after I choose the variables and select s

#include<iostream> #include<cmath> using namespace std; void operations( int a, int b){ int sum; sum =a+b; int product; product=a*b; } int main(){ int a,b; int sum; int product; char calc; cout<<"choose varaibles"; cin >> a>>b; cout<<" Choose operation"; cin>> calc; if (calc=='s') cout<<" sum is"<<sum; else if (calc=='p') cout<<" product is "<<product; operations(a,b); }

22nd Apr 2020, 3:09 PM
marya collegework
marya collegework - avatar
3 Respostas
+ 2
marya collegework , that's because you are calling your function by values (meaning :- you are sending copies of variables to the function not the actual function) Here👇is more information about passing by value and reference https://www.geeksforgeeks.org/difference-between-call-by-value-and-call-by-reference/
22nd Apr 2020, 3:24 PM
Arsenic
Arsenic - avatar
+ 2
And yes, remove those extra posts in your question , it is considered a bad practice here🙂🙃👍 https://www.sololearn.com/discuss/1316935/?ref=app
22nd Apr 2020, 3:27 PM
Arsenic
Arsenic - avatar
+ 1
İt's my first time writing a question here
22nd Apr 2020, 4:46 PM
marya collegework
marya collegework - avatar