c++ - Function that takes an array of integers as a parameter and returns the sum of odd numbers in the array -
i keep getting error: "run-time check failure #3 - variable 'x' being used without being initialized."
i thought initialized numbers put in array?
#include <iostream> using namespace std; const int max = 10; int odd(int sumodd[]) { int sum = 0; for(int = 0; < max; ++) { if(sumodd[i] % 2 != 0) sum+=sumodd[i]; } cout << "sum of odd integers in array: " << sum << endl; return sum; } int main() { int x[max] = {13,14,8,7,45,89,22,18,6,10}; int returnarray(x[max]); cout << "sum of odd integers in array" << endl; system("pause"); return 0; }
int returnarray(x[max]); // in main
should be
returnarray(x);
you've declared function taking array , returning integer, need call function array parameter.
Comments
Post a Comment