I'm a hell of confused as to when variable i became 10 , it still compared value 19 to value 96 which is var[8] and var[7] instead of var[10] and var[9].
#include <iostream>
#include <time.h>
#include <cstdlib>
usingnamespace std;
int main()
{
srand (time(NULL));
int var[10];
for (int i=0;i<10;cout<<var[i++]<<" ")
var[i]=rand()%100;
cout<<endl;
for (int i=9;i>0;i--){
while (var[i]<var[i-1] && cout<<"comparing "<<var[i]<<" to "<<var[i-1]<<endl)
{
swap(var[i],var[i-1]);
cout<<"Value "<<var[i]<<" switched to "<<var[i-1]<<endl;
cout<<"i was "<<i<<" after the switch . ";
i++;
cout<<"i is now "<<i<<endl<<endl;
}
}
cout<<endl;
for (int i=0;i<10;i++)
cout<<var[i]<<" ";
return 0;
}