|
-
December 3rd, 2005, 04:21 PM
#1
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|