+ 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); }
3 odpowiedzi
+ 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/
+ 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
+ 1
İt's my first time writing a question here