First c++ homework assignment

closed account (NURz8vqX)
I have to store names, ask for a users input name, add it to the stored list, display it, then remove a name from the list and display it. So far I have done this in an array. Can it be done in an array or does it have to be made in a vector instead? Here is my code. Please ignore the part about age, that is something I have to use after I finish the displaying of the lists.



#include <iostream>
#include<string>
using namespace std;


int main()
{
string last;
int age;

cout << "Please enter your last name: ";
cin >> last;
cout << "Please enter your age: ";
cin >> age;


string names[] ={"Jones","Smith","Whitney","Wang",last};

int size = sizeof(names)/sizeof(string);

for (int i=0; i < size; i++){
cout << names[i] <<endl;

}


}
Last edited on
java and c++ share a lot of similarities. It sounds to me like what you want to use is called a linked list of strings. I'd start by reading about linked lists in c++. I'm still a noob though, but it would make sense to me.

Also "print" is proper terminology if your talking about outputting to the terminal. Make sure you #include<isostream> and use cout to "print" as you say.
Topic archived. No new replies allowed.