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];

array[i+1]=key;}
for( i= 0; i< 6; i++)

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

Recommended Answers

All 3 Replies

Multiposted.

but did u c anything wrong with my code? im just a beginner.

Just solved it. thanks for people who at least watched it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.