Array beginner

Im not sure im doing this correctly, any help would be great.


#include <iostream>

using namespace std;

int main ()
{
float firstint,secondint,thirdint,fourthint,fifthint,Median;

cout << " Enter the First Integer" << endl;
cin >> firstint;

cout << "Enter the Second Integer" << endl;
cin >> secondint;

cout << "Enter the Third Integer " << endl;
cin >> thirdint;

cout<< "Enter the Fourth Integer" << endl;
cin >> fourthint;

cout << "Enter the Fifth Integer" << endl;
cin >> fifthint;

Median=
int swapHolder = -1;
int end=5;
int length =5;

int myArray[] = {firstint,secondint,thirdint,fourthint,fifthint};

for(int counter = length -1;counter > 0;counter-- )
{
for(int index=0; index <end; index++)
{
if(myArray[index] > myArray[index+1])
{
swapHolder=myArray[index+1];
myArray[index+1] = myArray[index];
myArray[index] = swapHolder;
}
}
end--;

for(int index = 0;index < 10; index++)
{
cout << myArray[index] << ",";
}
cout << endl;
cout << "Median = " << Median << endl;

return=0;


}
What exactly is your swapHolder variable meant to do?
#include <iostream>

using namespace std;

int main(){

float firstint,secondint,thirdint,fourthint,fifthint;

cout << " Enter the First Integer" << endl;
cin >> firstint;

cout << "Enter the Second Integer" << endl;
cin >> secondint;

cout << "Enter the Third Integer " << endl;
cin >> thirdint;

cout<< "Enter the Fourth Integer" << endl;
cin >> fourthint;

cout << "Enter the Fifth Integer" << endl;
cin >> fifthint;}

}
okay so i have this portion correct so the user can input integers but now i need the program to find the median of the numbers the user has inputted but i dont know how to do that
Hi,

Please always use code tags
http://www.cplusplus.com/articles/z13hAqkS/


okay so i have this portion correct so the user can input integers.....


Your variable names are confusing - you want them to be int, but you declared them as float. Prefer double rather than float, the precision of float is easily exceeded.

You are using arrays, so just use the array you have and get rid of variables firstint,secondint,thirdint,fourthint,fifthint

but now i need the program to find the median of the numbers the user has inputted but i dont know how to do that


So you need to sort the numbers, then the 3rd one will be the median.
Topic archived. No new replies allowed.