Looking at Run time error, My main field is not c++ computer programming. so mistakes can be occurred.
#include <iostream>
using namespace std;
const int MaxSize = 10;
// Implementation of functions
void insert(float a[], int& n, float x)
{
if (n == 0 || a[n - 1] <= x)
{
a[n] = x;
}
else
{
a[n] = a[n - 1];
int i = n - 1;
insert(a, i, x);
}
if (n < MaxSize)
{
n++;
}
}
int main()
{
float a[MaxSize];
int n = 0;
// Test
float testArray[] = { 20.0, 5.0, 30.0, 50.0, 2.0, 50.5, 25.5, 40.0, 100.0, 80.0, 70.0 };
for (int i = 0; i < 11; i++)
{
insert(a, n, testArray[i]);
}
for (int i = 0; i < n; i++)
{
cout << a[i] << "\n";
}
// To pause
cin.get();
cin.get();
return 0;
}
On my Machine This Program Executes Where the Prototype Occurs and definition occurs.
regards;
so how to remove run time error.
regards;
/*Looking at Run time error, My main field is not c++ computer programming. so mistakes can be occurred*/
#include <iostream>
using namespace std;
const int MaxSize = 10;
// Implementation of functions
void insert(float a[], int& n, float x)
{
if (n == 0 || a[n - 1] <= x)
{
a[n] = x;
}
else
{
a[n] = a[n - 1];
int i = n - 1;
insert(a, i, x);
}
if (n < MaxSize)
{
n++;
}
}
int main()
{
float a[MaxSize];
int n = 0;
// Test
float testArray[] = { 20.0, 5.0, 30.0, 50.0, 2.0, 50.5, 25.5, 40.0, 100.0, 80.0, 70.0 };
for (int i = 0; i < 11; i++)
{
insert(a, n, testArray[i]);
}
for (int i = 0; i < n; i++)
{
cout << a[i] << "\n";
}
// To pause
cin.get();
cin.get();
return 0;
}
Comments
Leave a comment