new to c++ 'trying to figure out functions

This is a discussion on new to c++ 'trying to figure out functions within the C++ Programming forums, part of the General Programming Boards category; Ok been messin with this code to try and better my understanding of c++, was hoping someone could help me ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    38

    new to c++ 'trying to figure out functions

    Ok been messin with this code to try and better my understanding of c++, was hoping someone could help me out.
    I commented in the code where i was specificly looking of help. Messed with it can't figure it out. Thanks in advance.
    Code:
    #include "stdafx.h"
    #using <mscorlib.dll>
    #include <tchar.h>
    #include <stdlib.h>
    #include <iostream>
    #include <conio.h> 
    using namespace std;
    using namespace System;
    
    	double intUsersAge();
    	double intCurDate();
    	void mShowAge(double, double);
    	int mfintQuitYN();
    	void mfBlank(int);
    
    int _tmain()
    {
    	double dlbUsersAge;
    	double dlbCurDate;
    	int intQuit;
    	
    	
        
    	dlbUsersAge = intUsersAge();			
    	dlbCurDate = intCurDate();	
    	
    	do
    	{	
    		
    		system("CLS");
    		dlbUsersAge = intUsersAge();
    		dlbCurDate = intCurDate();
    		mShowAge(dlbUsersAge, dlbCurDate);
    		
    
            intQuit = mfintQuitYN();
    
    	}while (intQuit == 0);
    
    	return 0;
    }
    
    void mShowAge(double dlbUsersAge, double dlbCurDate)
    {
    	
    	cout << "You are " << dlbCurDate - dlbUsersAge << " Years Old as of today!\n";
    	cout << "\n";
    	if ((dlbCurDate - dlbUsersAge)>= 90)
    	{
    		cout << "\nYou getting pretty old there...\n";
    	}
    	if (dlbCurDate - dlbUsersAge >= 50 && dlbCurDate - dlbUsersAge <= 89)
    	{
    		cout << "Congrates, your middle aged...or alittle over\n";
    		cout << "\n";
    		cout << "You've outlived most others in third world countries....you must be proud\n";
    	}
    	if (dlbCurDate - dlbUsersAge >= 18 && dlbCurDate - dlbUsersAge <= 49)
    	{
    		cout << "Your in the prime of your life...lucky dog you\n";
    	}
    	if (dlbCurDate - dlbUsersAge >= 10 && dlbCurDate - dlbUsersAge <= 17)
    	{
    		cout << "The crystal ball says your body is changing and you\n";
    	cout << "be wantin yourself a car pretty soon.\n";
    	}
    	if (dlbCurDate - dlbUsersAge >= 1 && dlbCurDate - dlbUsersAge <= 9)
    	{
    		cout << "Learning to crawl, then walk, then ride your tri-cycle, gotsta love it.\n";
    	}
    	if (dlbCurDate - dlbUsersAge >= -100 && dlbCurDate - dlbUsersAge <= 0)
    	{
    		cout << "HOW ARE YOU HERE?!\n";
    	}
    
    }
    double intUsersAge()
    {
    double intAge;
    	
    	Console::Write("Year you were born was? : ");
    	intAge = Convert::ToDouble(Console::ReadLine());
    		mfBlank(2);
    
    	return intAge;
    }
    
    double intCurDate()
    {
    	double intAge;
    	
    	Console::Write("Enter current Date Please : ");
    	intAge = Convert::ToDouble(Console::ReadLine());
    		mfBlank(2);
    
    	return intAge;
    
    }
    
    int mfintQuitYN()   //<------HOW WOULD I MAKE THIS LOOP WITH A Y AND y INSTEAD OF 0.  TRIED CONVERTING, 
    //BUT CAN'T DUE TO LOSS OF DATA.  TRIED DECLARING DIFFERENTLY SUCH AS VOID...
    //BUT NOT LUCK SO HELP IS NEEDED HERE.  
    //OH AND WOULD LIKE TO KEEP IT IN THIS DEFINED FUNCTION.
    {
    	
    	int intReturn;
    	
    		mfBlank(2);
    		cout << "Enter 0 to Try Again or any other number to Quit: ";
    cin >> intReturn;
    	
    
    
    
    	return intReturn;
    }
    void mfBlank(int intBlank )  //ALSO HERE IF I TRY AND USE MFBLANK TO SPACE IN THE SHOWAGE FUNCTION, IT TELLS ME
    //ITS UNDECLARED, BUT IT WORKS IN OTHERS, IS THAT SOMETHING
    //SPECIAL ABOUT IF STATEMENTS?
    {
    	int intCount = intBlank;
    
    	do
    	{
    		cout <<"\n";
    	    intCount = intCount - 1;
    
    	} while (intCount > 0);
    	
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    I think you need to go read a better book on C++

    #using <mscorlib.dll> // nobody elses compiler knows about this
    #include <tchar.h> // no idea what this is
    #include <stdlib.h> // this is a C header, but written in old-style C++
    #include <iostream> // this is a C++ header, written in new style C++
    #include <conio.h> // this is a DOS header

    And what's with using
    cout << "HOW ARE YOU HERE?!\n";
    in some places, and
    Console::Write("Enter current Date Please : ");
    in others?

    > int _tmain()
    More non-standard code

    Not only are you severly limiting the number of people who can help you (to those that have your compiler), you're pretty much tying yourself to only being able to program for that compiler.
    Sure all that non-standard stuff has a place, but not when you're learning C++.

    So try it again using only
    #include <iostream>
    and only cin and cout for input and output.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    38
    sorry, I'm just playing around with this code, I realize it had alot of stuff it that was exactly needed. I was just trying different things and see what happened, and changing it to different things, sometimes forgetting to take out unused stuff.

    #include <conio.h> was needed for the cls, clear screen
    ...the others I don't really recall what I used them for,
    at the time I needed them just as the conio one, but I don't remember.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    You're writing a Managed C++ application. This is the first thing to change. Start a Win32 Console Application project and choose Empty Project from the options.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is it legal to have functions within functions?
    By Programmer_P in forum C++ Programming
    Replies: 13
    Last Post: 05-25-2009, 11:21 PM
  2. An array of macro functions?
    By someprogr in forum C Programming
    Replies: 6
    Last Post: 01-28-2009, 06:05 PM
  3. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. functions - please help!!!!
    By linkies in forum C Programming
    Replies: 1
    Last Post: 08-21-2002, 07:53 AM

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