Hello cblack618,
I do not know what the directions that you were given look like, but let us look at what you have posted a bit differently.
For this assignment, you will use pointers to write a program that asks the user to enter the name,
birth city and year of birth for five (5) family members.
1. Be sure to include comments throughout your code where appropriate.
2. The data should be stored in dynamically created parallel arrays.
3. Users are assumed to be born between the years 1900 and 2018, and should enter the year of birth
in one of the two formats 19XX and 20XX.
4. Output the data from the arrays in a formatted table.
|
Putting this in one block of type may save some space, but it is hard to read and pick out what you need to do. Also numbering can help.
Looking at #1 this is something that should be done as you code. The compiler does not care about comments nor does it include them in the compiled code. This is also true for white space, i.e., blank lines. But this does make a difference in how the code reads. Thinking that you will go back later and add comments does not help you when writing the code.
As I said the first thing you need to do is get the input to have something to work with before you can work on output.
Looking at your code, which does not compile or follow the directions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <iostream>
#include <string>
#include <iomanip>
int main()
{
string * name = nullptr;
string * birthcity = nullptr;
string * birthyear = nullptr;
cout << "Enter your name" << endl;
getline(cin, *firstname);
cout << "Enter your birth city" << endl;
getline(cin, *lastname);
char* person[3]{ "name", "Birthplace", "Birthyear" }
char* charles[3] = { "Charles Blackwell", "12/2/1980", "michigan" }
return 0;
}
|
I changed some of the layout to make it easier to see what is happening.
Lines 1 - 9 is a good start. Lines 7 - 9 define pointers and sets them to "nullptr"s which is good. After that you have missed point 2 of the directions.
Line 12 is trying to use the variable "firstName" which is never defined. The same is true for line 15.
You have also missed entering the birth city and birth year.
For lines 17 and 18. With line 18 being indented should be the first hint that something is wrong with these two lines.
Looking deeper into lines 17 and 18.
char* person[3]
defines a three element array of type "char*", ("char" pointer), which can only hold an address to a "char", but you are trying to store a string in these elements and that does not work. Also these two lines have no business or reason to be in the program.
In line 18 you have
"12/2/1980"
, but the variable name "birthYear" alludes to only needing the year not the rest.If you enter a full date you will need extra code to extract the year. Do not think that is what you want to de.
Before you can even think about output you need to get the program accepting input and to follow the directions.
againtry's first response gives you one possible solution for your input. One thing I would suggest is in place of
using namespace std;
I would use:
1 2 3
|
using std::cin;
using std::cout;
using std::string;
|
This will narrow the focus to what you need and also help you to learn what is in the standard name space.
Also I would put line 7 inside "main" because for now it does not need to be a global variable. "LIMIT" is an OK name, but I would be more likely to choose "MAX_ARRAY_SIZE" or just "MAXSIZE" as this tends to give the name a better understanding of what it is used for. Then I would give it the type "size_t", an alais for "unsigned int" because where it is used you can only use positive numbers and most of the time these numbers will be greater than (0) zero.
After that the only question is on line 13. Should the variable type be an "int" or a string". This would depend on what you need to do with the "birthYear" after it is entered.
When you correct your program to get the input then we can work on the output.
Hope that helps,
Andy