-
September 8th, 2009, 05:44 PM
#1
[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
-
September 8th, 2009, 05:48 PM
#2
Re: void value not ignored as it ought to be
Originally Posted by javajax
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.
-
September 8th, 2009, 06:39 PM
#3
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
-
September 8th, 2009, 06:45 PM
#4
Re: void value not ignored as it ought to be
Originally Posted by javajax
[/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.
-
September 8th, 2009, 06:56 PM
#5
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.
-
September 8th, 2009, 07:01 PM
#6
Re: void value not ignored as it ought to be
Originally Posted by javajax
i have read what i believe to be a good description and sample...
Link, please.
Originally Posted by javajax
...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.
Originally Posted by javajax
...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.
-
September 8th, 2009, 07:17 PM
#7
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?
-
September 8th, 2009, 07:28 PM
#8
Re: void value not ignored as it ought to be
Originally Posted by javajax
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).
-
September 8th, 2009, 07:37 PM
#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
-
September 8th, 2009, 07:45 PM
#10
Re: void value not ignored as it ought to be
Originally Posted by javajax
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.
-
September 8th, 2009, 08:02 PM
#11
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
-
September 8th, 2009, 08:06 PM
#12
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() % (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.
-
September 8th, 2009, 09:52 PM
#13
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|