i'm trying to make a program that will square a set of numbers from 0 to "int" which i set to be 25, but can be anywhere from 0 to 1000, and print the results in two columns. the first column is the original number and the second the squared number. i got a bunch of errors and i don't understand why i got them. i'm just looking for some guidance.
here is what i have :
CODE
#include <iostream>
#include <vector>
using namespace std;
void square(int& ml,vector<int>& sq);
int main()
{
vector<int> squares;
int maxlen = 0;
void square(maxlen, squares)
{
int k=25;
if(k=>0 && k<10){ml = 1;}
else if(k=>10 && k<100){ml = 2;}
else if(k=>100 && k<1000){ml = 3;}
else {cout << "error";}
for(int i=0; i!=k; ++i){
int x=i^2;
sq.push_back(x);}
}
vector::size_type vec_len = squares.size();
for(int i=0; i!=vec_len; ++i){
int len = 0
if(i=>0 && i<10){len=1;}
else if(i=>10 && i<100){len=2;}
else if(i=>100 && i <1000){len=3;}
else
cout<<"error";
cout << i << string(maxlen + 1 -len) << squares.[i];
}
return 0;
}
and here are the errors i got:
squareprg.cpp: In function ‘int main()’:
squareprg.cpp:13: error: variable or field ‘square’ declared void
squareprg.cpp:13: error: initializer expression list treated as compound expression
squareprg.cpp:13: error: cannot convert ‘std::vector<int, std::allocator<int> >’ to ‘int’ in initialization
squareprg.cpp:14: error: expected ‘,’ or ‘;’ before ‘{’ token
squareprg.cpp:27: error: ‘template<class _Tp, class _Alloc> class std::vector’ used without template parameters
squareprg.cpp:27: error: expected `;' before ‘vec_len’
squareprg.cpp:28: error: ‘vec_len’ was not declared in this scope
squareprg.cpp:31: error: expected ‘,’ or ‘;’ before ‘if’
squareprg.cpp:32: error: expected primary-expression before ‘else’
squareprg.cpp:32: error: expected `;' before ‘else’
squareprg.cpp:33: error: expected primary-expression before ‘else’
squareprg.cpp:33: error: expected `;' before ‘else’
squareprg.cpp:34: error: expected primary-expression before ‘else’
squareprg.cpp:34: error: expected `;' before ‘else’
squareprg.cpp:37: error: invalid conversion from ‘int’ to ‘const char*’
squareprg.cpp:37: error: initializing argument 1 of ‘std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]’
i know it's a lot to ask and i'd be happy if i only got help with 1 error, i've just been over all the errors and can't figure it out. i'm new so go easy lol. thanks in advance.