Question: I am encountering an uninitialized local variable in the main function. This error occurs on the line with the code getInput(word, def, n); under the

I am encountering an uninitialized local variable in the main function. This error occurs on the line with the code "getInput(word, def, n);" under the function "int main(). This error came after i fixed the "getInput" function. In that case, I was getting a redefinition of formal parameters for "word" and "def". In that function a had lines of code " string* word = new string[n];" and "string* def = new string[n]; ". I changed those to "word = new string[n];" and "def = new string[n];". This then caused my problem.

C++ Code:

#include #include using namespace std;

// Function declarations void getInput(string* &word, string* &def, int n); void output(string* &word, string* &def, int n);

int main() { int n; string* word; string* def; cin.ignore(); //ignore buffer getInput(word, def, n); output(word, def, n);

return 0; }

// Function definitions void getInput(string* &word, string* &def, int n) {

cout << "How many terms do you want the dictionary to hold? "; cin >> n; word = new string[n]; ; // array to store words def = new string[n]; // array to store definitions

for (int i = 0; i < n; i++) { cout << " Enter Term " << i + 1 << ": "; getline(cin, word[i]); cin.clear(); // clearing the buffer cout << "Enter the definition for \"" << word[i] << "\": "; getline(cin, def[i]); } }

void output(string* &word, string* &def, int n) { cout << " You entered:" << endl; for (int i = 0; i < n; i++) { cout << i + 1 << ". " << word[i] << ": " << def[i] << endl; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!