+ 1
Why this code doesn't work?
#include <iostream> using namespace std; void sf(int a, int b){ int c = a / 100 * b; } int main() { int c; int x = 100; int y = 10; sf(x, y); cout<<c<<endl; return 0; }
2 Answers
+ 1
This should produce the result you're looking for:
#include <iostream>
using namespace std;
int sf(int a, int b){
return (a / 100 * b); // a = x, b = y, returns 10
}
int main() {
int x = 100;
int y = 10;
int c = sf(x, y); // c = 10
cout<<c<<endl;
return 0;
}
0
This code work but your sf function just do no modifications.
This is because a and b are no references and sf return nothing.
The c you declared in sf is not the one in main.