compiled ok but no execution

*sort 3 numbers from highest to lowest by functions*/

#include<stdio.h>

void read(int & v1,int & v2, int & v3) {
printf("enter first number\n");
scanf("%d",&v1);
printf("\n enter second number\n");
scanf("%d",v2);
printf("\n enter third number\n");
scanf("%d",v3);
}
void sort(int &v1, int &v2, int &v3) {
int aux;

if (v3>v2) {
aux=v2;
v2=v3;
v3=aux;
}
if (v2>v1) {
aux=v1;
v1=v2;
v2=aux;
}
if (v2<v3) {
v2=aux;
v3=v2;
v3=aux;
}

}

void print(int v1, int v2, int v3){
printf("numbers are sorted %d, %d, %d \n",v1,v2,v3);
}
int main() {
int number1,number2,number3;
char key;
key='y';


while (key!='n') {
read(number1,number2,number3);
sort(number1,number2,number3);
print(number1,number2,number3);
scanf("%c",&key);
}
}





Last edited on
It's executing, it's just closing right away and not doing anything. Look at your main:

1
2
3
4
5
6
7
8
9
10
int main() {
int number1,number2,number3;
char key;
key='y';   // you assign 'y' to key


while (key=='n') {  // and loop while key == 'n'
//...
}
}


Note that since key never is 'n' (you initialized it with 'y'), the loop will never run.

You probably meant to do while(key == 'y') ?
thanks a lot, i corrected it but it keeps giving error before getting the 3rd number...
Last edited on
Topic archived. No new replies allowed.