Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren0
Sum and Average in functions. It compiled but the result is showing garbage value. could anyone write the proper form of code an
#include<iostream> using namespace std; int sum (int,int); int average (int, int); int main () { int num1; int num2; cout<<"\nEnter first Value:"; cin>> num1; cout<<"\nEnter second Value:"; cin>> num2; sum (num1,num2); average (num1,num2); cout<<"\nThe sum is:" << " " << sum; cout<<"\nThe average is:" << " " << average; return 0; } int sum ( int a, int b) { return (a + b); } int average (int a, int b) { return (sum (a,b)/2); }
3 Antworten
+ 1
Dipanjan Basu Kindly check for the corrections made.
https://code.sololearn.com/ckh58fvjcWHv/?ref=app
0
average should return double (or other type of decimal I dont really know C++)
0
And you have to store the values you return from your functions