I've created a database using a switch statement and functions and I believe I've gotten it working but for whatever reason case B only works after the second try. It's probably a simple fix but any help is appreciated. Thank you.
#include <iostream>
#include <string>
int main() {
using namespace std;
char getMenuChoice();
void addAlbm(string alb[], int rls[], int& itemIndex);
void lstAlbms(string alb[], int rls[], int size);
string albms[10];
int rleseYear[10], index = 0;
do {
switch (toupper(getMenuChoice())) {
case 'A':
addAlbm(albms, rleseYear, index);
break;
case 'B':
lstAlbms(albms, rleseYear, index); //works after 2 tries
break;
case 'Q':
cout << "\n""Goodbye" << endl;
exit(0);
default:
cout << "\n""**Invalid choice**""\n" << endl;
}
} while (toupper(getMenuChoice()) != 'Q');
return 0;}
void addAlbm(std::string alb[], int rls[], int &itemIndex) {
using namespace std;
string newAlbm;
int newRleseYear;
cout << "\n""Enter album: ";
cin.ignore(50, '\n');
getline(cin, newAlbm);
cout << "\n""Enter year: ";
cin >> newRleseYear; cout << "\n";
alb[itemIndex] = newAlbm;
rls[itemIndex] = newRleseYear;
itemIndex++;}
void lstAlbms(std::string alb[], int rls[], int size) {
using namespace std; cout << endl;
for (int y = 0; y < size; y++)
cout << alb[y] << "\t" << rls[y] << endl;
cout << endl;}
char getMenuChoice() {
using namespace std;
char choice;
cout << "--Main Menu--" << endl;
cout << "\n""A. Add items" << endl;
cout << "B. List items" << endl;
cout << "Q. Quit" << endl;
cout << "\n""Choose an option""_ _ _ _ _ _ _ ";
cin >> choice;
return choice;}