Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,460 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,112 people online right now. Registration is fast and FREE... Join Now!




compiling errors need help finding out what i'm doing wrong

 
Reply to this topicStart new topic

compiling errors need help finding out what i'm doing wrong

talby
5 Feb, 2008 - 04:41 PM
Post #1

New D.I.C Head
*

Joined: 24 Jan, 2008
Posts: 9

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.
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: Compiling Errors Need Help Finding Out What I'm Doing Wrong
5 Feb, 2008 - 04:46 PM
Post #2

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,010



Thanked: 7 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
take your function sqaure out of the main(), see what happens and post the updated code and the new errors, if any.
User is offlineProfile CardPM
+Quote Post

talby
RE: Compiling Errors Need Help Finding Out What I'm Doing Wrong
5 Feb, 2008 - 05:12 PM
Post #3

New D.I.C Head
*

Joined: 24 Jan, 2008
Posts: 9

CODE

#include <iostream>
#include <vector>

using namespace std;

void square(int& ml,vector<int>& sq)
{
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);}
}        

int main()
{
vector<int> squares;
int maxlen = 0;

void square(maxlen, squares)        

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 errors:

squareprg.cpp: In function ‘void square(int&, std::vector<int, std::allocator<int> >&)’:
squareprg.cpp:10: error: expected primary-expression before ‘>’ token
squareprg.cpp:11: error: expected primary-expression before ‘>’ token
squareprg.cpp:12: error: expected primary-expression before ‘>’ token
squareprg.cpp: In function ‘int main()’:
squareprg.cpp:25: error: variable or field ‘square’ declared void
squareprg.cpp:25: error: initializer expression list treated as compound expression
squareprg.cpp:25: error: cannot convert ‘std::vector<int, std::allocator<int> >’ to ‘int’ in initialization
squareprg.cpp:27: error: expected ‘,’ or ‘;’ before ‘vector’
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>]’
squareprg.cpp:37: error: expected unqualified-id before ‘[’ token

i'm really confused about what i'm missing in lines 10-12 and in lines 31-34

This post has been edited by talby: 5 Feb, 2008 - 05:13 PM
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: Compiling Errors Need Help Finding Out What I'm Doing Wrong
5 Feb, 2008 - 05:20 PM
Post #4

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,010



Thanked: 7 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
maxlen is an integer not a pointer to integer, so in the sqaure function, use &maxlen when you call it from the main, also check if there are any semicolons missing
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Compiling Errors Need Help Finding Out What I'm Doing Wrong
5 Feb, 2008 - 08:10 PM
Post #5

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,347



Thanked: 51 times
Dream Kudos: 25
My Contributions
Your function prototpye is till in your main function.
User is online!Profile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 01:49PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month