Hello guys, i am trying to write an insertion sort program with any values entered by any users but im getting some weird numbers. could someone help me see what s wrong with my code. this is my code:

#include <iostream>
using namespace std;
int main()

int a,b,c,d,e,f;
int array[6]= {a,b,c,d,e,f};
int i,j,key;
cout <<"enter a value: ";
cin >> a;

cout <<"enter a value: ";
cin >> b;

cout <<"enter a value: ";
cin >> c;

cout <<"enter a value: ";
cin >> d;

cout <<"enter a value: ";
cin >> e;

cout <<"enter a value: ";
cin >> f;

for (j=1; j < 6; j++){

key = array[j];

for (i=j-1; (i>=0) && (array[i]>key); i--)

array[i+1]= array[i];

for( i= 0; i< 6; i++)

cout<< array[i]<<" ";
return 0;

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

8 Years
Discussion Span
Last Post by peter_budo

Didn't get an answer instantly and decided to just post your question again, did you?

That's not going to make you friends, you know. Now noone will bother to look at your question and try to help.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.