True or false statments used in my return...

This is a discussion on True or false statments used in my return... within the C++ Programming forums, part of the General Programming Boards category; Geetings; I am having problems getting my program to output a true or false statement. It should decide whether i ...

  1. #1
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    Exclamation True or false statments used in my return...

    Geetings;
    I am having problems getting my program to output a true or false statement. It should decide whether i input the correct parameters if my loan is either approved or disapproved.
    Help!

    Code:
    #include <iostream>		
    using namespace std;
    
    bool CreditApproved(double, double, double);
    
    double income, assests, liabilities;;
    
    int main()
    {
    
    	cout <<"Input your income (must be at least $25,000) or your assests\n"
    		 <<"(which must beat least $100,000). Include your total liabilities \n"
    		 <<"that must be less than $50,000.\n";
    	
    	cin >>  income >> assests >> liabilities;
    	
    	cout << " My loan application is " << CreditApproved(income, liabilities, assests) <<"\n";
    	return 0;
    
    }
    
    bool CreditApproved(double liabilities, double income, double assests)
    {
    
    	if (liabilities < 50,000)
    		if (income > 25,000)
    			if (assests > 100,000)
    				return true;
    	else 
    		return false; 
    }
    #include <iostream>		
    using namespace std;
    
    bool CreditApproved(double, double, double);
    
    double income, assests, liabilities;;
    
    int main()
    {
    
    	cout <<"Input your income (must be at least $25,000) or your assests\n"
    		 <<"(which must beat least $100,000). Include your total liabilities \n"
    		 <<"that must be less than $50,000.\n";
    	
    	cin >>  income >> assests >> liabilities;
    	
    	cout << " My loan application is " << CreditApproved(income, liabilities, assests) <<"\n";
    	return 0;
    
    }
    
    bool CreditApproved(double liabilities, double income, double assests)
    {
    
    	if (liabilities < 50,000)
    		if (income > 25,000)
    			if (assests > 100,000)
    				return true;
    	else 
    		return false; 
    }
    Thanks!


  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    When you try to output a boolean value, it will be handled as an integer, so it will show as a number. Try this:

    Code:
    cout << " My loan application is " << (CreditApproved(income, liabilities, assests) ? "approved" : "declined") <<"\n";
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    Smile Thanks!

    That solved it!
    Thanks XSquared!

  4. #4
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511
    You can also use the boolalpha manipulator to print out the true or false values- not the 0 or 1:

    Code:
    cout << boolalpha << CreditApproved(income, liabilities, assests);
    Mr. C.

  5. #5
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    Wink cool

    I learned something new! Thanks Mr. C!
    That helped me out also.

  6. #6
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072

    Re: True or false statments used in my return...

    Originally posted by correlcj

    Code:
    bool CreditApproved(double liabilities, double income, double assests)
    {
    if (liabilities < 50,000)
        if (income > 25,000)
            if (assests > 100,000)
                return true;
    else 
        return false; 
    }
    DANGER!!

    This will not work the intended way!

    Your code is equivalent to this: (C++ doesn't care about indentation)

    Code:
    if (liabilities < 50,000)
        if (income > 25,000)
        {
            if (assests > 100,000)
                return true;
            else 
                return false; 
        }
    
    //NO RETURN!
    Change the code, or it will not behave as expected!
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 07:14 AM
  2. BIG problem. How do I find a bug in so much code?
    By Yarin in forum C++ Programming
    Replies: 44
    Last Post: 01-31-2008, 11:39 AM
  3. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  4. Reducing Code size from ridiculous length
    By DanFraser in forum C# Programming
    Replies: 10
    Last Post: 01-18-2005, 04:50 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 09:01 PM

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