CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Apr 2009
    Location
    chicago
    Posts
    9

    [RESOLVED] void value not ignored as it ought to be

    i have a function that seems simple but you know those simple ones.

    Code:
    void Vecs (vector <int> & v1, vector <int> & v2, int s1, int s2)
    {
    	for (int i = 0; i < v1.size() and i < v2.size(); i++)
    	{
    		v1[i] = srand(s1) % RND_NO_RANGE + 1;
    		v2[i] = srand(s2) % RND_NO_RANGE + 1;
    	}
    }
    i am also getting this error

    Code:
    ub2.cc: In function ‘void Vecs(std::vector<int, std::allocator<int> >&, std::vector<int, std::allocator<int> >&, int, int)’:
    sub2.cc:91: warning: comparison between signed and unsigned integer expressions
    sub2.cc:91: warning: comparison between signed and unsigned integer expressions
    sub2.cc:93: error: void value not ignored as it ought to be
    sub2.cc:94: error: void value not ignored as it ought to be
    sub2.cc: In function ‘void print_vec(const std::vector<int, std::allocator<int> >&)’:
    sub2.cc:107: warning: comparison between signed and unsigned integer expressions
    the warning on 91 is an unwritten function and on 107 i am not sure what the warning is.

    could someone help me get rid of this error

  2. #2
    Join Date
    Jun 2006
    Location
    M31
    Posts
    885

    Re: void value not ignored as it ought to be

    Quote Originally Posted by javajax View Post
    could someone help me get rid of this error
    Uh, check srand's signature. What you're doing makes no sense. You probably intended to write rand, instead.

  3. #3
    Join Date
    Apr 2009
    Location
    chicago
    Posts
    9

    Re: void value not ignored as it ought to be

    i have changed the srand to rand and now i get another error

    Code:
    void Vecs (vector <int> & v1, vector <int> & v2, int s1, int s2)
    {
    	for (int i = 0; i < v1.size() and i < v2.size(); i++)
    	{
    		if	(i < v1.size())	
    			v1[i] = rand(s1) % (RND_NO_RANGE + 1);
    		if (i < v2.size())
    			v2[i] = rand(s2) % (RND_NO_RANGE + 1);
    	}
    }
    here are the errors
    Code:
    sub2.cc: In function ‘void Vecs(std::vector<int, std::allocator<int> >&, std::vector<int, std::allocator<int> >&, int, int)’:
    sub2.cc:91: warning: comparison between signed and unsigned integer expressions
    sub2.cc:91: warning: comparison between signed and unsigned integer expressions
    sub2.cc:93: warning: comparison between signed and unsigned integer expressions
    /usr/include/stdlib.h:380: error: too many arguments to function ‘int rand()’
    sub2.cc:94: error: at this point in file
    sub2.cc:95: warning: comparison between signed and unsigned integer expressions
    /usr/include/stdlib.h:380: error: too many arguments to function ‘int rand()’
    sub2.cc:96: error: at this point in file
    sub2.cc: In function ‘void print_vec(const std::vector<int, std::allocator<int> >&)’:
    sub2.cc:109: warning: comparison between signed and unsigned integer expressions
    i am not to familiar with using rand i have a seed number and need to use those for each rand, also i have a limit which i am trying to use

  4. #4
    Join Date
    Jun 2006
    Location
    M31
    Posts
    885

    Re: void value not ignored as it ought to be

    Quote Originally Posted by javajax View Post
    [/code]
    here are the errors
    Code:
    /usr/include/stdlib.h:380: error: too many arguments to function ‘int rand()’
    i am not to familiar with using rand...
    Start by reading the documentation. Trial and error usually doesn't work in programming.

  5. #5
    Join Date
    Apr 2009
    Location
    chicago
    Posts
    9

    Re: void value not ignored as it ought to be

    i have read what i believe to be a good description and sample however when i seem to write my own i get errors first being the "error: void value not ignored as it ought to be" i believe i need a better reference and that is what i am looking for on the internet. could you recommend a reference, or help me find this error.

  6. #6
    Join Date
    Jun 2006
    Location
    M31
    Posts
    885

    Re: void value not ignored as it ought to be

    Quote Originally Posted by javajax View Post
    i have read what i believe to be a good description and sample...
    Link, please.

    Quote Originally Posted by javajax View Post
    ...could you recommend a reference...
    As usual, your best references are the C (ISO/IEC 9899) and/or C++ (ISO/IEC 14882) standards. Their respective drafts are available online for free.

    Quote Originally Posted by javajax View Post
    ...or help me find this error.
    Your compiler already did that; rand takes no arguments.
    Last edited by Plasmator; September 8th, 2009 at 07:13 PM. Reason: Fixed typo.

  7. #7
    Join Date
    Apr 2009
    Location
    chicago
    Posts
    9

    Re: void value not ignored as it ought to be

    i have found 2 mentions of srand in your reference neither really helped me.
    i know i have found the problem but i don't understand why it is happening. can you explain to me why it is happening?

  8. #8
    Join Date
    Jun 2006
    Location
    M31
    Posts
    885

    Re: void value not ignored as it ought to be

    Quote Originally Posted by javajax View Post
    can you explain to me why it is happening?
    Why are you looking at srand when your error is related to rand?

    Regardless, rand takes no arguments.
    You, on the other hand, are trying to pass something to it. That's what's causing your error(s).

  9. #9
    Join Date
    Apr 2009
    Location
    chicago
    Posts
    9

    Re: void value not ignored as it ought to be

    ok so guess my question is how to effectively use srand with multiple seeds i have now eliminated my errors but do not fully understand the concept

    Code:
    void Vecs (vector <int> & v1, vector <int> & v2, int s1, int s2)
    {
    	for (int i = 0; i < v1.size() and i < v2.size(); i++)
    	{
    		if	(i < v1.size())
    		{
    			srand(s1);
    			v1[i] = rand() % (RND_NO_RANGE + 1);
    		}
    		if (i < v2.size())
    		{
    			srand(s2);
    			v2[i] = rand() % (RND_NO_RANGE + 1);
    		}
    	}
    }
    I believe what I need is a good explanation and tutorial

  10. #10
    Join Date
    Jun 2006
    Location
    M31
    Posts
    885

    Re: void value not ignored as it ought to be

    Quote Originally Posted by javajax View Post
    I believe what I need is a good explanation and tutorial
    See the MSDN entries for srand and rand. Ignore the MS-specific parts (e.g., *_s versions), of course.

    I don't know what kind of "tutorial" you're expecting because it doesn't get any simpler than this.

  11. #11
    Join Date
    Apr 2009
    Location
    chicago
    Posts
    9

    Re: void value not ignored as it ought to be

    Thank you for the links i think i understand srand and rand better. I still don' understand what is wrong with my code thought the one i just put up. rand has no arguments and srand is starting the seed so why is it not working. is there a good way to use 2 seeds

  12. #12
    Join Date
    Apr 2009
    Location
    chicago
    Posts
    9

    Re: void value not ignored as it ought to be

    Code:
    void Vecs (vector <int> & v1, vector <int> & v2, int s1, int s2)
    {
    	srand(s1);
    	for (int i = 0; i < v1.size(); i++)
    			v1[i] = rand() &#37; (RND_NO_RANGE + 1);
    	srand(s2);
    	for (int i = 0;i < v2.size(); i++)
    			v2[i] = rand() % (RND_NO_RANGE + 1);
    }
    Ok i think I have everything I need.
    Thank you for the references and help microsoft.com was really good for me.

  13. #13
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,721

    Re: [RESOLVED] void value not ignored as it ought to be

    You should only call srand once at the start of the program.
    What are s1 and s2 supposed to represent when you call
    srand() ?

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