Today I wrote a code using array, but it said: 1 unresolved externals. What the heck is going on here in my code ?
include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int Max(int array[], int a)
{
int max = array[0];
for (int i = 0; i < a; i++)
{
if (max < array[i] )
{
max = array[i];
}
}
return max;
}
int Min(int array[], int b)
{
int min = array[0];
for (int i = 0; i < b; i++)
{
if (min > array[i])
{
min = array[i];
}
}
return min;
}
int main()
{
int array[50];
srand(time(NULL));
array[50] = rand() % 100;
cout << "The smallest number: " << Min(array, 50) << endl;
cout << "The highest number: " << Max(array, 50) << endl;
}
The full error message should include the name of whatever the thing is which was unresolved. It would help if you copy+paste the exact message as it appeared.
Unrelated to your question, this line is an error:
array[50] = rand() % 100;
This is an out-of-bounds access. The array has valid subscripts from 0 to 49 inclusive. Here an attempt is made to store a value in the 51st element, which is outside the array. The outcome is undefined - but generally something bad is likely to happen (though it might not be apparent).
The rest of the array is uninitialised - it contains garbage values.
I guess you wanted to use a loop to assign values to each of the array elements.
It said:
1>------ Build started: Project: Practice problem 2 page 147, Configuration: Debug Win32 ------
1> Source.cpp
1>c:\users\admin\documents\visual studio 2015\projects\practice problem 2 page 147\practice problem 2 page 147\source.cpp(32): warning C4244: 'argument': conversion from 'time_t' to 'unsigned int', possible loss of data
1>MSVCRTD.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
1>C:\Users\Admin\documents\visual studio 2015\Projects\Practice problem 2 page 147\Debug\Practice problem 2 page 147.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Here WinMain is the clue. it looks as though your project is set up to create a windows application, instead of a console application.
I'm not familiar with visual studio, but I think you need to try to create a fresh project, making sure you select 'console' as the project type. Then copy your existing code into that new project.