Thread: hopeless little c program

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    6

    Question hopeless little c program

    Hello,

    I'm working on a project where I'll calculate a persons age using birthdate and current date supplied by user.
    I can't get the age to print out as an integer.

    as an additional comment I had already added if and else if statements further make the calculations depending on the date entered but had taken them out to revert back to beginning to get the print out right before moving on.

    Code:
    /* this program will calculate a person's age based on the current year and person's birthdate then print results.*/
    
    
    #include "stdafx.h"
    //function declarations
    
    void getBirthDate(int* birthDay, int* birthMonth, int* birthYear);
    void getCurrentDate(int* currentDay, int* currentMonth, int* currentYear);
    int calculateAge(int currentYear,int birthYear);
    void printResults(int birthYear, int birthMonth, int birthDay, int currentYear, int currentMonth, int currentDay);
    
    
    int main(void)
    
    {
    	//local declarations
    	int birthYear;
    	int birthMonth;
    	int birthDay;
    	int currentDay;
    	int currentMonth;
    	int currentYear;
    	int age;
    	
    //statements
    
    	getBirthDate(&birthDay, &birthMonth, &birthYear);
    	getCurrentDate(&currentDay, &currentMonth, &currentYear);
    	calculateAge(birthYear,currentYear);
    	printResults (birthYear, birthMonth, birthDay, currentYear, currentMonth, currentDay);
    	age = calculateAge(birthYear, currentMonth);
    	
    	return 0;
    } //main
    
    /* ===================================getBirthDate=============================
    This function reads the birthYear input by the user at the keyboard
    Pre parameter save the dates as integer values in birthYear, birthMonth and birthDay 
    Post Data read into parameter address
    */
    
    void getBirthDate(int* birthDay, int* birthMonth, int* birthYear)
    
    {
    
    		//statements
    	
    	printf("Please Enter your birth date in  dd, mm, yyyy format: \n");
    	scanf_s("%d %d %d",birthDay,birthMonth,birthYear);
    		
    	return ;
    
    } //getbirthYear
    
    /* ===================================getCurrentDate=============================
    This function reads the Current input by the user at the keyboard
    Pre parameter save the dates as integer values in birthYear, birthMonth and birthDay 
    Post Data read into parameter address
    */
    
    void getCurrentDate(int* currentDay, int* currentMonth, int* currentYear)
    
    { 
    
    		//statements
    	
    	printf("Please Enter the current date in  dd, mm, yyyy format: \n");
    	scanf_s("%d%d%d",currentDay,currentMonth,currentYear);
    	
    	
    	return ;
    
    } //getCurrentDate
    
    /* ==================================CalculateAge=============================================
    this function will calculate an age based on the two dates given
    pre
    Post returns age
    */
    int calculateAge(int currentYear, int birthYear)
    {
    //local declarations
    
    int age;
    
    //Statements
    
    age = currentYear - birthYear;
    
    						printf("you are %d\n");
    	
     return age;
    
    } //calculateAge
    
    /* =======================================printResult=====================================================
    prints the current date, birthdate and person's age
    */
    void printResults(int birthYear, int birthMonth, int birthDay, int currentYear, int currentMonth, int currentDay)
    {
    	//local declarations
    
    
    	//statements
    
    	printf("Your birthday is %d,%d,%d\n", birthDay, birthMonth, birthYear);
    	printf("The current date is %d,%d,%d\n", currentDay,currentMonth, currentYear);
    	//printf("you are %d\n", age);
     
    	return ;
    } // printResult
    Last edited by beone2; 06-17-2009 at 05:25 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM