problem>

This is a discussion on problem> within the C++ Programming forums, part of the General Programming Boards category; Hi there this is a very easy problem but i can't get it correctly here's the code; Code: #include <iostream> ...

  1. #1
    Registered User
    Join Date
    May 2006
    Location
    in your head
    Posts
    49

    problem>

    Hi there this is a very easy problem but i can't get it correctly here's the code;

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main(void)
    {
    
    int yr_of_brth, crnt_yr;
    
    cout << "Year of Birth" << endl;
    cin >> yr_of_brth;
    cin.ignore();
    cout << "\n";
    cout << "Current Year" << endl;
    cin >> crnt_yr;
    cin.ignore();
    cout << "\n";
    
    cout << "your age is: " << abs(yr_of_brth - crnt_yr) << endl;
    cin.get();
    }
    
    Output:
    Year of birth
    62
    Current Year
    99
    Your age is: 37
    
    -----another run of the program-----
    Output:
    Year of birth
    62
    Current Year
    00
    Your age is: 38
    the thing that i dont get is if I input 62 for year of birth and current year for 00 i got a answer of 62 not 38..... how can i get 38 as a answer because this program requires only the last two numbers in year.... any help there? thanks

  2. #2
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Maybe something like if the current year is less than the birth year add 100 to the current year... haven't tested it and don't plan on it since this is homework, I have had this assignment before. Had me stumped for a while.

  3. #3
    Registered User
    Join Date
    May 2006
    Location
    in your head
    Posts
    49
    thanks mate now i have an idea......

  4. #4
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    Does this sound vaguely like the Y2K bug to anyone else!!?
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

Popular pages Recent additions subscribe to a feed

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