Hello guys this is my first time using stackoverflow and hope that you would oblige me.
so I was learning coding from codecademy and I was stuck in this project
Question- Write a program to find the sum of even numbers and the product of odd numbers in a vector.
//my code
#include <iostream>
#include <vector>
int main()
{
std::cout << " This program is written to calculate the sum of even numbers and product of odd numbers\n";
std::cout << "When you are done then plz press f";
std::string ans;
int k;
std::cin >> ans;
while (ans != "f") {
std::cout << "Plz enter your number:";
std::cin >> k;
std::vector<int> num;
num.push_back(k);
}
if (ans == "f") {
std::cout << "Thanks for trying this program\n"
<< "your Answers are\n";
for (int i = 0; i <= num.size(); i++)
if (num[i] % 2 == 0) {
int even = even + num[i];
}
else {
int odd = odd + num[i];
}
}
std::cout << "Sum of even numbers is " << even << "\n";
std::cout << "Sum of odd numbrs is " << odd << "\n";
}
error being shown-
review.cpp: In function ‘int main()’:
review.cpp:18:26: error: ‘num’ was not declared in this scope
for (int i = 0; i <= num.size() ;i++)
^~~
review.cpp:18:26: note: suggested alternative: ‘enum’
for (int i = 0; i <= num.size() ;i++)
^~~
enum
review.cpp:26:47: error: ‘even’ was not declared in this scope
std::cout << "Sum of even numbers is " << even << "\n";
^~~~
review.cpp:27:45: error: ‘odd’ was not declared in this scope
std::cout << "Sum of odd numbrs is " << odd << "\n";
^~~
review.cpp:27:45: note: suggested alternative: ‘void’
std::cout << "Sum of odd numbrs is " << odd << "\n";
^~~
void