hi,
I am trying to compile this program to compute the Present Value using the following code, and I think my main() function is flawed. Any help would be really appreciated.
#include <cmath>
#include <vector>
#include <iostream>
using std::cout;
using std::endl;
sorry Disch
here goes..
when I compile it (I run the following $:g++ bacpp.cpp -o test), I get the following errors:
bacpp.cpp:7: error: expected ',' or '...' before '(' token
bacpp.cpp:7: error: ISO C++ forbids declaration of 'vector' with no type
bacpp.cpp: In function 'int cfd(int)':
bacpp.cpp:10: error: 'cft' was not declared in this scope
bacpp.cpp:12: error: 'cfa' was not declared in this scope
bacpp.cpp:10: In function 'int main()':
bacpp.cpp:10: error: invalid conversion from 'int(*)[3]' to 'int'
bacpp.cpp:10: error: too many arguments to function 'int cfd(int)'
bacpp.cpp:10: error: at this point in file
Vectors are in the std namespace. You either need to do using std::vector; with your other using lines, or you need to change line 7 to have std:: before all the vectors.
problem #2:
main is passing arrays to the function, not vectors. If you want to pass vectors to the function, then main needs to make vectors instead of arrays.
problem #3:
When passing things to a function by reference (which is what you're doing), you do not use the & operator. That operator gives you a pointer.
This line:
cout<<cfd(&a1,&a2,&r)<<endl; <- get rid of all those '&' symbols
bacpp.cpp: In function 'int main()':
bacpp.cpp:21: error: braces around initializer for non-aggregate type 'ivec'
bacpp.cpp:21: error: braces around initializer for non-aggregate type 'ivec'