Thread: Help with basic C++ program

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    14

    Help with basic C++ program

    Can someone tell me what is wrong with this code? I've got everything except the 24,36,48, and 60 month calculations working. They turn out to zero everytime. I think it has something to do with where I input noMonths, but I can't make this work. Can someone help please????? Pretty please???? Oh and they will say 24,36,48,60 at the ends of the 0.00 because I was trying to see if it would read noMonths.

    Thanks

    Code:
    
    
    
    #include <iostream>
    #include <cmath>
    #include <iomanip>
    
    using namespace std;
    
    int main()
    
    	{
    		// Declare Variables
    
    		float price;
    		float downPayment;
    		float tradeIn;
    		float loanAmt;
    		float annualIntRate;
    		float annualIntPercent;
    		float monIntRate;
    		float monPayment;
    		int   noMonths;
    
    
    
    	void getPrice(float&);
    	void getTradeIn(float&, float&);
    	void getDownPayment(float&, float&, float&);
    	void getInterestRate(float&);
    	void calcMonPayment(float&, int&, float&, float&, float&, float&, float&, float&);
    
    	getPrice(price);
    	getTradeIn(tradeIn, price);
    	getDownPayment(downPayment, price, tradeIn);
        getInterestRate(annualIntRate);
        calcMonPayment(loanAmt, noMonths, monPayment, downPayment, price, monIntRate, tradeIn, annualIntRate);
    	
    	annualIntPercent = annualIntRate*100;
    
    	cout << setw(50) << "Honest Dave's Used Cars. \n\n";
    
    	cout << setw (30) << "Vehicle Price" << fixed << setprecision(2) << setw(20) << price << endl;
    	cout << setw (30) <<  "Trade In Value" << fixed << setprecision(2) << setw(20) << tradeIn << endl;
    	cout << setw (30) <<  "Down Payment" << fixed << setprecision(2) << setw(20) << downPayment << endl;
    	cout << setw (50) << "                       _________________________" << endl;
    	cout << setw (30) << "Loan Amount" << fixed << setprecision(2) << setw (20) << loanAmt << endl << endl;
    	
    	cout << setw (30) << "Annual Interest Rate" << fixed << setprecision(2) << setw(20) << annualIntPercent << "%" << endl << endl;
    	cout << setw (50) << "Monthly Payment Options \n\n";
    
        
    
    	   noMonths = 24;
    			 cout << setw (30) << "24 Months" << fixed << setprecision(2) << setw(20) << monPayment << noMonths << endl;
    	   noMonths = 36;
    			cout << setw (30) << "36 Months" << fixed << setprecision(2) << setw(20) << monPayment << noMonths << endl;
    	   noMonths = 48;
    			cout << setw(30) << "48 Months" << fixed << setprecision(2) << setw(20) << monPayment << noMonths << endl;
    	   noMonths = 60;
    			cout << setw(30) << "60 Months" << fixed << setprecision(2) << setw(20) << monPayment << noMonths << endl;
    
    		cin.ignore();
    		cin.get();
    		return 0;
    	}
    
    
    
    //********************************************************************************************************************************
    
    
    void getPrice(float& price)
    {
    	bool dataInvalid = true;
    		while(dataInvalid)
    			{
    			cout << "Please enter vehicle price. \n";
    			cin >> price;
    			if (price < 50.00)
    				{
    				cout << "Price of vehicle is less than $50.00. Please re-enter vehicle price. \n";
    				dataInvalid = true;
    				}
    				else if (price > 50000.00)
    				{
    				cout << "Price of vehicle is greater than $50,000.00. Please re-enter vehicle price. \n";
    				dataInvalid = true;
    				}
    				else {
    					dataInvalid = false;
    					}
    				return ;
    		}
    }
    //******************************************************************************************************************************
    
    void getTradeIn (float& tradeIn, float& price)
    {
    	bool dataInvalid = true;
    		while(dataInvalid)
    			{
    				cout << "Please enter Trade In value of the vehicle to be traded in. \n";
    				cin >> tradeIn;
    				if (tradeIn < 0)
    					{
    						cout << "Trade in value is less than zero. Please re-enter the trade in value. \n";
    						dataInvalid = true;
    					}
    					else if (tradeIn > price)
    					{
    						cout << "Trade in value is higher than price of vehicle to be bought. Please re-enter the trade in value. \n";
    						dataInvalid = true;
    					}
    					else
    					{
    						dataInvalid = false;
    					}
    					return;
    		}
    }
    //*********************************************************************************************************************************
    
    void getDownPayment(float& downPayment, float& price, float& tradeIn)
    {
    	bool dataInvalid = true;
    		while(dataInvalid)
    			{
    				cout << "Plase enter a down payment amount. \n";
    				cin >> downPayment;
    				if (downPayment < 0)
    					{
    						cout << "Down payment amount is less than zero. Please re-enter the down payment amount. \n";
    						dataInvalid = true;
    					}
    					else if (downPayment > (price - tradeIn))
    					{
    						cout << "Down payment amount is higher than the price of the vehicle less the trade in value. Please re-enter down payment amount. \n";
    						dataInvalid = true;
    					}
    					else
    					{
    						dataInvalid = false;
    					}
    					return;
    		}
    }
    //**********************************************************************************************************************************
    
    void getInterestRate( float& annualIntRate)
    {
    	bool dataInvalid = true;
    		while(dataInvalid)
    			{
    				cout << "Please enter the annual interest rate in decimal form. 6% will be .06. \n";
    				cin >> annualIntRate;
    				if (annualIntRate < 0)
    					{
    						cout << "Annual interest rate is less than zero. Please re-enter the annual interest rate. \n";
    						dataInvalid = true;
    					}
    					else if (annualIntRate > .50)
    					{
    						cout << "Annual interest rate is great than 50%. Please re-enter the annual interest rate. \n";
    						dataInvalid = true;
    					}
    					else
    					{
    						dataInvalid = false;
    					
                            
    					}
    					return;
    		}
    }
    //**********************************************************************************************************************************
    
    void calcMonPayment(float& loanAmt, int& noMonths, float& monPayment, float& downPayment, float& price, float& monIntRate, float& tradeIn, float& annualIntRate )
    {
    	loanAmt = price - downPayment - tradeIn;
    	monIntRate = annualIntRate/12;
    monPayment=(loanAmt*monIntRate)/(1.0-pow((monIntRate+1), -noMonths));
    
    
    		return;
    }
    
    //**********************************************************************************************************************************

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    14
    Never mind. Got it!!

    (does happy dance!!)

    Thanks anyway!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. Basic encryption program???
    By Finchie_88 in forum C++ Programming
    Replies: 14
    Last Post: 09-10-2004, 09:01 AM
  3. IDEA: A basic drawing program
    By ygfperson in forum Contests Board
    Replies: 0
    Last Post: 08-12-2002, 11:15 PM
  4. Replies: 2
    Last Post: 05-10-2002, 04:16 PM
  5. Help me with this basic c program
    By [ToXiC]-[LeaK] in forum C Programming
    Replies: 1
    Last Post: 01-28-2002, 11:44 PM