What's the problem in my code?
Hello, I hope you're all feeling good. I'm a newbie to the world of coding, Actually I've just started learning programming with no previous knowledge. I'm trying to create a menu of multiple selections in c++ but when I choose to see the average or the smallest item, my code crashes and keeps looping forever (my code is not complete yet it's only a demo)..! Please help me find out what I'm doing wrong. Thank you in advance. #include <iostream> #include <vector> using namespace std; int main() { vector <int> numbers; char selection {}; do{ cout <<"\nP - Print list" <<endl; cout <<"A - Add new number" <<endl; cout <<"M - Display average" <<endl; cout <<"S - Show smallest" <<endl; cout <<"L - Show largest" <<endl; cout <<"Q- Quit" <<endl; cout <<"\nEnter You choice: " <<endl; cin >> selection; if (selection == 'p' || selection == 'P') { if (numbers.size()==0) cout <<" [] - List is empty" <<endl; else { cout << "[ "; for (auto val:numbers){ cout << val << " " ;} cout << "]"; } } // first sentence else if (selection == 'a' || 'A') { int item {}; cout << "Please enter the item: "<< endl; cin >> item; numbers.push_back(item); cout << item << " is added" << endl; } // second sentence else if (selection == 'M' || selection == 'm') { if (numbers.size()==0) cout << "List is empty, Please add items" << endl; else { int total {0}; for (auto val:numbers) { total+=val; } cout << " the average is: " << total/numbers.size() << endl; } } else if (selection == 's' || selection == 'S') { int min {}; for (auto val:numbers) if (val>min) min=val; cout << "Smallest number is : " << min << endl; } } while (selection != 'q' && selection != 'Q'); cout << "Goodbye.."<< endl ; return 0; }