### Error Message

Hi Guys. I'm doing an assignment for uni, and I'm getting a message I don't understand. I've researched other examples, and I don't see a difference, perhaps someone can shed some light. The assignment involves a random number generator and bubble sort.

- The error message is,"Warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data"

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182`` ``````//Random Number Generator //With Bubble Sort and Selection Sort #include #include #include using namespace std; void bubblesort(); //Bubble Sort Function int random; int randqty [1000]; //Array Storing Random Numbers int main() { srand(time(0)); //Error message points to this line. Ive tried using 'NULL' too. int range; int option; cout << "How many random numbers would you like sorted?"; cin >> random; cout << "Within which range would you like these random numbers?"; cin >> range; for (int i = 1; i > option; switch (option) { case 1: { system ("cls"); cout << "Bubble Sort\n"; bubblesort(); break; } case 2: { system ("cls"); cout << "Selection Sort\n"; break; } default: { system ("cls"); cout << "Please enter another choice\n"; break; } } return 0; } void bubblesort(int randqty[], int random) { int temp; bool swap; do { swap = false; for (int x=0; x < random-1; x++) { if (randqty[x] > randqty[x+1]) { temp = randqty[x]; randqty[x]=randqty[x+1]; randqty[x+1]=temp; swap=true; } } }while (swap); }``````

Thank-you in advance.
That isn't an error, it's just a warning. You should be able to ignore it.

Function time() returns a value of type `time_t`
Function srand() takes a parameter of type `unsigned int`
The compiler automatically converts from one to the other, and is simply letting you know that there may be some loss of precision.

If considered necessary, you could suppress the message by using an explicit cast, using either ` srand((unsigned int) time(0));`
or ` srand(static_cast<unsigned int>(time(0)));`
Last edited on
Thank - you Chervil, spot on.

If I could ask about one more error message...
"error LNK2019: unresolved external symbol "void __cdecl bubblesort(void)" (?bubblesort@@YAXXZ) referenced in function _main"

I have no idea about this? A Google search says I may be missing a library, I just have no idea which one?
You say bubblesort does not take any argument
You use bubblesort without passing any parameters
You define a bubblesort that must take an array and its size as parameters.
¿see the problem?

You should learn about scope

By the way, `random' is not a good name for the size of an array.
Last edited on
In your code above, you have defined function bubblesort at line 60 like this:
`void bubblesort(int randqty[], int random)`
That is, it requires two input parameters, the first is an array of integers, the second is an integer.

However, the declaration on line 9
`void bubblesort();`
is a function which takes no parameters at all.

As far as the compiler is concerned, these are two different functions.
On line 40, the function is called, with no parameters. The compiler thinks this is ok, as it matches the declaration on line 9. But the linker tries to match the function call to the code or the function, but cannot find it.

Hence it is the linker which outputs the error message.

In this case, it looks like the correct version is the one on line 60.
You need to change both the prototype declaration (line 9) and the call on line 40, so they each supply the required parameters, so as to agree with line 60.

Here's a recent thread where the role of the prototype is discussed in a bit more detail: http://www.cplusplus.com/forum/beginner/88749/#msg476413
Thank-you once again, all input is greatly appreciated.
Topic archived. No new replies allowed.