CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2005
    Posts
    1

    Arrow Basic while loop question

    Hi everyone,

    I am just starting any programming in C++ and I can't manage to make the following code work.

    What I am trying to do basically is : 1) Ask the user for a number of periods
    2) For period from 0 to the number of periods entered by the user in 1) have 3 vectors created of cash flows, discount rates and periods concerned with each cash flow (= from start_period to end_period each time until end_period = total number of periods).

    Code:
    #include <cmath>
    #include <algorithm>
    #include <vector>
    #include <cstdio>
    #include <cstdlib>
    #include <iostream>
    using std::cout;
    using std::cin;
    using std::endl;
    using namespace std ;
    #include "fin_recipes.h"
    #include "cash_flow_irr_discrete.h"
    #include "cash_flow_pv_discrete.h"
    #include "test_present_value.h"
    int main()
    {
    	int number_of_periods=1;
    	int period = 0;
    	int start_period = 0;
    	int end_period = 0;
    	int counter = 0;
    	double cash_flow;
    	double r;
    	vector<double> times;
    	vector<double> cflows;
    	vector<double> discountrate;
    	cout <<"enter total number of cash flow periods including 
                    zero cash flow periods if any :";
    	cin >> number_of_periods;
    
    	while( period != number_of_periods )
    	{
    		period = end_period;
    		cout <<"enter cash flow amount :";
    		cin>> cash_flow ;
    		cout<<"from period :";
    		cin>> start_period ;
    		if (start_period < end_period) { 
                                    cout <<"error : starting cash-flow period
                                    last preceding ending cash-flow period" ; } ;
    		cout<<"to period :";
    		cin>> end_period ;
    
                                    if (end_period > number_of_periods) 
    		{ 
    	                cout <<"error : last cash-flow period > total number of 
                                    periods" ;
    		end_period=start_period;
    		} ;
    		if (end_period < start_period) { cout <<"error : end 
                                    period for the cash-flow < start period for the cash-
                                    flow" ; } ;
    
    		cout<<"enter discount rate :";
    		cin>> r ;
    			
    		for (int counter = start_period; counter <= end_period; 
                                    counter++)
    		{
    		cflows.push_back(cash_flow);
    		times.push_back(counter);
    		discountrate.push_back(r);
    		};
    	}
    cout <<"calculation starting" ;
    }
    Last edited by cilu; December 3rd, 2005 at 04:38 PM. Reason: code tags added

  2. #2
    Join Date
    Jul 2005
    Location
    Bremen, Germany
    Posts
    33

    Smile Re: Basic while loop question

    Ur query is not so clear ..

    the code compiles..
    kings4u

  3. #3
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Basic while loop question

    Give us some more information please.
    What error do you get?
    Compile time error?
    Runtime error?
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured