Hello everyone,
I’m doing the challenge activities for the chapter on functions. The chapter before it was on vectors, and the task is as follows: Call a function (first_three_multiples) which takes an integer, and then returns a vector with the first 3 multiples of that integer. For example, first_three_multiples(5) should yield a vector with 5, 10, and 15.
#include
#include
// Define first_three_multiples() here:
std::vector first_three_multiples(int num){
std::vector numv(3);
numv[0]=num;
numv[1]=2num;
numv[2]=3num;
return numv;
};
int main() {
first_three_multiples(8);
for(int i=0; i < first_three_multiples;i++){
std::cout << first_three_multiples[i];
}
}
This is my code so far. I’m receiving an error message about the for loop at the end: “main.cpp: In function ‘int main()’:
main.cpp:20:20: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
for(int i=0; i < first_three_multiples;i++){
^~~~~~~~~~~~~~~~~~~~~
main.cpp:21:41: warning: pointer to a function used in arithmetic [-Wpointer-arith]
std::cout << first_three_multiples[i];”
Apparently I violated some rule, what did i do?
^