Vectors, Review, It telling me that elseif is some sort of variable

Hello. I hope you guys are having a good day.
I am on the vectors review and I decided that I would create a program to test my coding skills, but I encountered an error that’s telling me that elseif is some sort of variable that has not been defined.
I don’t know what to do.
I would appreciate your help on this topic.

Here’s a link:

https://www.codecademy.com/courses/learn-c-plus-plus/lessons/cpp-vectors/exercises/review

Here’s the code:

#include

#include

int main() {

std::vectorNumbers = {0, 0, 0};

int storage = 0;

std::cout <<“Welcome to the even and odd numbers calculator\n”;

std::cout <<“Please enter first number (single digit only)\n”;

std::cin >> storage;

Numbers.push_back(storage);

std::cout <<“Next number please\n”;

std::cin >> storage;

Numbers.push_back(storage);

std::cout <<“And anoter one\n”;

std::cin >> storage;

Numbers.push_back(storage);

std::cout <<“Anoter one\n”;

std::cin >> storage;

Numbers.push_back(storage);

std::cout <<“And anoter one\n”;

std::cin >> storage;

Numbers.push_back(storage);

std::cout <<“Thank you, Here is your anser.\n”;

double even = 0;

double odd = 0;

for (int i = 0; i < Numbers.size(); i++) {

if (Numbers[i] == 1) {

odd = odd + Numbers[i];

}

elseif (Numbers[i] == 2) {

even = even + Numbers[i];

}

elseif (Numbers[i] == 3) {

odd = odd + Numbers[i];

}

elseif (Numbers[i] == 4) {

even = even + Numbers[i];

}

elseif (Numbers[i] == 5) {

odd = odd + Numbers[i];

}

elseif (Numbers[i] == 6) {

even = even + Numbers[i];

}

elseif (Numbers[i] == 7) {

odd = odd + Numbers[i];

}

elseif (Numbers[i] == 8) {

even = even + Numbers[i];

}

elseif (Numbers[i] == 9) {

odd = odd + Numbers[i];

}

}

std::cout <<“Sum of Even numbers\n”;

std::cout << even<<"\n";

std::cout <<“Sum of Odd numbers\n”;

std::cout << odd<<"\n";

std::cout <<“Thankyou for using the Even and Odd Numbers Calculator\n”;

}

Here’s a screenshot:

Sorry it is not showing “include iostream” and “include vector”.

Thanks for your help and support. :slight_smile:

Hi
You need a space between else and if;
e.g
else if (Numbers[i] == 6)

Hope that helps

It worked! Thankyou. I’ll make sure not to make that mistake next time :+1:

1 Like