need help keep getting error in the #include \"stdafx.h\" of the code. //Header
ID: 3838469 • Letter: N
Question
need help keep getting error in the #include "stdafx.h" of the code.
//Header file
#include "stdafx.h"
#include <iostream>
using namespace std;
//Function prototypes
void BubbleSort(int arr[], int);
void SelectionSort(int arr[], int);
//Main function
void main()
{
int array1[8] = { 3,5,7,1,9,4,3,7 };
int array2[8] = { 3,5,7,1,9,4,3,7 };
int i;// loop variable
// Displaying contents of first array
cout << "contents of first array;" << endl;
for (i = 0; i < 8; i++)
cout << "" << array1[i];
cout << endl;
//function call to sort using bubble sort
BubbleSort(array1, 8);
//Displaying contents of second array
cout << "Contents of second array:" << endl;
for (i = 0; i < 8; i++)
cout << "" << array2[i];
cout << endl;
//Function call to sort using SelectionSort
SelectionSort(array2, 8);
system("pause");
}//end main
//function defenitions
void BubbleSort(int array[], int size)
{
bool swap;
int temp;
cout << "Bubble sort" << endl;
do
{
swap = false;
for (int count = 0; count < (size - 1); count++)
{
if (array[count] > array[count + 1])
{
temp = array[count];
array[count] = array[count + 1];
array[count + 1] = temp;
swap = true;
}
}
for (int i = 0; i < size; i++)
cout << array[i] << "";
cout << endl;
} while (swap);
}
void SelectionSort(int array[], int size)
{
int startScan, minIndex, minValue;
cout << "Selection Sort:" << endl;
for (startScan = 0; startScan < (size - 1); startScan++)
{
minIndex = startScan;
minValue = array[startScan];
for (int index = startScan + 1; index < size; index++)
{
if (array[index] < minValue)
{
minValue = array[index];
minIndex = index;
}
}
array[minIndex] = array[startScan];
array[startScan = minValue];
for (int i = 0; i < size; i++)
cout << array[i] << "";
cout << endl;
}
}
Explanation / Answer
#include "stdafx.h" basically works with visual studio .
I have removed #include "stdafx.h" and maid void main() to int main() and added a return statement
Here is fixed code
#include <iostream>
using namespace std;
//Function prototypes
void BubbleSort(int arr[], int);
void SelectionSort(int arr[], int);
//Main function
int main()
{
int array1[8] = { 3,5,7,1,9,4,3,7 };
int array2[8] = { 3,5,7,1,9,4,3,7 };
int i;// loop variable
// Displaying contents of first array
cout << "contents of first array;" << endl;
for (i = 0; i < 8; i++)
cout << "" << array1[i];
cout << endl;
//function call to sort using bubble sort
BubbleSort(array1, 8);
//Displaying contents of second array
cout << "Contents of second array:" << endl;
for (i = 0; i < 8; i++)
cout << "" << array2[i];
cout << endl;
//Function call to sort using SelectionSort
SelectionSort(array2, 8);
//system("pause");
return 0;
}//end main
//function defenitions
void BubbleSort(int array[], int size)
{
bool swap;
int temp;
cout << "Bubble sort" << endl;
do
{
swap = false;
for (int count = 0; count < (size - 1); count++)
{
if (array[count] > array[count + 1])
{
temp = array[count];
array[count] = array[count + 1];
array[count + 1] = temp;
swap = true;
}
}
for (int i = 0; i < size; i++)
cout << array[i] << "";
cout << endl;
} while (swap);
}
void SelectionSort(int array[], int size)
{
int startScan, minIndex, minValue;
cout << "Selection Sort:" << endl;
for (startScan = 0; startScan < (size - 1); startScan++)
{
minIndex = startScan;
minValue = array[startScan];
for (int index = startScan + 1; index < size; index++)
{
if (array[index] < minValue)
{
minValue = array[index];
minIndex = index;
}
}
array[minIndex] = array[startScan];
array[startScan = minValue];
for (int i = 0; i < size; i++)
cout << array[i] << "";
cout << endl;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.