0

I'm very new to C++ and for my assignment they want me to create a function that gets the users input which I've done here: (classList is an array)

public:
    void userInput() {

        string enterAgain;

        do {

        cout << "Enter the students name: " << name;
        cin >> name;

        cout << "Enter the number of classes the student is enrolled in: " << numClasses;
        cin >> numClasses;

        for (int i = 0; i < numClasses; i++) {
            cout << "Enter the class list: " << (i+1) << classList;
            cin >> classList;
            i++;
        }

        cout << "Would you like to enter again (y for yes): " << enterAgain;
        cin >> enterAgain;

        } while (enterAgain == "Y" || enterAgain == "y");

    }

When I run the program it will ask the user for the students name followed by the number of classes they're taking, but when it ask the user to input the class list it displays something like this:

Enter the class list: 0x7fff536d1b78

But in addition to this it won't let me input anything. I searched for hours trying to correct this problem and I was hoping someone could point me in the right direction in correcting this problem. Thanks!

mur7ay
  • 803
  • 3
  • 16
  • 44
  • 1
    `<< classList` prints the address of the array `classList`. why would you print that? and if `classList` is an array, you need to place values at its **indices**. – Swastik Padhi Oct 27 '15 at 02:10
  • I still full understand how to work with arrays, but the instructions were "A function that inputs all values from the user, including the list of class names." – mur7ay Oct 27 '15 at 02:18
  • yes and it's doing just that. I believe the contents of the array `classList` was intended by the instructions where they said **class names**. – Swastik Padhi Oct 27 '15 at 02:22

1 Answers1

1
public:
    void userInput() {

        string enterAgain;

        do {

        cout << "Enter the students name: " << name;
        cin >> name;

        cout << "Enter the number of classes the student is enrolled in: " << numClasses;
        cin >> numClasses;

        for (int i = 0; i < numClasses; i++) {
            cout << "Enter the class list: " << (i+1) << classList;
            cin >> classList;
            i++;
        }

        cout << "Would you like to enter again (y for yes): " << enterAgain;
        cin >> enterAgain;

        } while (enterAgain == "Y" || enterAgain == "y");

    }

should be-

public:
    void userInput() {

        string enterAgain;

        do {

        cout << "Enter the students name: " << endl;
        cin >> name;

        cout << "Enter the number of classes the student is enrolled in: " << endl;
        cin >> numClasses;

        for (int i = 0; i < numClasses; i++) {
            cout << "Enter the class list: " << (i+1) << endl;
            cin >> classList[i];
        }

        cout << "Would you like to enter again (y for yes): " << endl;
        cin >> enterAgain;

        } while (enterAgain == "Y" || enterAgain == "y");

    }
Swastik Padhi
  • 1,849
  • 15
  • 27