c - Bubble sort not working at all, if statement not executing -


i'm working on program going used sort students test scores , retrieve mean, median, , mode of scores. strange reason bubble sort not working.. i'm unsure why.

#include <stdio.h> #include <stdlib.h>  #include <string.h> #define n 3  int main (void) {  char vstudents[n][15], trans = 'y', vtemp2; int vscores[n], vtemp, x, = 0, j=0, newn;  printf("\t\twhatsamatta u scores system\n\n");  {     printf("please enter students name: ");     gets(vstudents[i]);     trans = 'n';     while (trans == 'n')     {         printf("enter students score: ");         scanf("%d", &vscores[i]);         fflush(stdin);          if (vscores[i] >= 0 & vscores[i] <= 100)             trans = 'y';         else              printf("score invalid, please re-enter score.\n");     }     i++;     j++; } while (j != n);   for(x = 0; x < n - 1; x++) {        if ((x < n - 1) && (vscores[i] > vscores[i + 1]))     {         vtemp = vscores[i];         vscores[i] = vscores[i + 1];         vscores[i + 1] = vtemp;         x = -1;     } }  printf("%d %d %d\n\n", vscores[0], vscores[1], vscores[2]);  system("pause"); return 0; 

any useful, in advance!

at least 1 error:

for(x = 0; x < vscores[n] - 1; x++) {       if ((x < vscores[n] - 1) && (vscores[n] > vscores[n + 1]))    { 

should be

 for(x = 0; x <n - 1; x++)  {        if ((x < n - 1) && (vscores[n] > vscores[n + 1]))     {      //^^you should not compare index x array elements 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -