-
Pointers program
Hello Gurus:
I have been trying to create this program using pointers, below is what I have done so far, however I am not quite getting the pointers part.
I have created a program that will prompt the user for the current year (integer), their current age (integer), and the number of years married (integer).
I have to use pointers, display the year of the person’s 25th anniversary, the year of the person’s 50th anniversary, and how old they will be on both their 25th and 50th anniversaries.
This is what I have so far:
(see attached cpp file)
Will someone who knows about pointers see if you help me out.
Thanks
Desperate
Jamina
-
Pointers problem
Thanks for letting me know about the code tags, I am new to this forum, just trying to get some help from others.
Thanks
Jamina
Code:
#include<iostream>
int main()
{
int year_now, age_now, number_years_married ;
cout << "Enter the current year then press RETURN.\n";
cin >> year_now;
cout << "Enter your current age in years.\n";
cin >> age_now;
cout << "Enter the number of years married.\n";
cin >> number_years_married;
return 0;
}
-
Was your assignment more specific on where/how to use pointers? This does not seem like a program where you would even need pointers...
-
Hmm...
Code:
#include<iostream>
int main()
{
int *year_now = new int;
int *age_now = new int;
int *number_years_married = new int;
cout << "Enter the current year then press RETURN.\n";
cin >> *year_now;
cout << "Enter your current age in years.\n";
cin >> *age_now;
cout << "Enter the number of years married.\n";
cin >> *number_years_married;
delete year_now;
delete age_now;
delete number_years_married;
return 0;
}
or....
Code:
void Input(int *year_now, int *age_now, int *number_years_married);
int main()
{
int year_now;
int age_now;
int number_years_married;
Input(&year_now, &age_now, &number_years_married);
return 0;
}
void Input(int *year_now, int *age_now, int *number_years_married)
{
cout << "Enter the current year then press RETURN.\n";
cin >> *year_now;
cout << "Enter your current age in years.\n";
cin >> *age_now;
cout << "Enter the number of years married.\n";
cin >> *number_years_married;
}