Pointers program

This is a discussion on Pointers program within the C++ Programming forums, part of the General Programming Boards category; Hello Gurus: I have been trying to create this program using pointers, below is what I have done so far, ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    6

    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
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    6

    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;
    }

  3. #3
    Registered User codegirl's Avatar
    Join Date
    Jun 2003
    Posts
    76
    Was your assignment more specific on where/how to use pointers? This does not seem like a program where you would even need pointers...
    My programs don't have bugs, they just develop random features.

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    249
    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;
    
    }
    Last edited by funkydude9; 08-06-2003 at 02:45 PM.
    Well, there are a few things wrong with your code:

    1) It does not work.
    2) It does not work.
    3) It does not work.

    Hope this helps.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need some pointers on program
    By noob2c in forum C++ Programming
    Replies: 7
    Last Post: 12-14-2003, 04:16 AM
  2. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 04:23 PM
  3. Replies: 2
    Last Post: 03-13-2003, 08:40 AM
  4. Help In Visualising Pointers ( C Program )
    By Evilelmo in forum C Programming
    Replies: 5
    Last Post: 01-25-2003, 12:48 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21