Hi my program is functioning properly and doing all it is supposed to do, but i just cant get the bloody thing to exist with the while loop
can anyone tell me why this is happening? or how to fix it?
Code:
#include <stdio.h>
int rotate_right(int);
int rotate_left(int);
int encode(int, int);
int main(void){
int shift, ch;
printf("Enter a number for amount of rotation: ");
scanf("%d",&shift);
printf("Enter text to scramble: ");
while((ch = getchar())!=EOF){
ch = encode(ch,shift);
putchar(ch);
}
return 0;
}
int encode(int ch, int shift){
while(shift!=0){
if(shift>0){
ch = rotate_right(ch);
shift--;
}
else if(shift<0){
ch = rotate_left(ch);
shift++;
}
}
return ch;
}
int rotate_right(int ch){
if((ch >= 'A'&& ch < 'Z')||(ch >= 'a'&& ch < 'z'))
ch++;
else if(ch == 'Z')
ch = 'A';
else if(ch == 'z')
ch = 'a';
return ch;
}
int rotate_left(int ch){
if((ch > 'A'&& ch <= 'Z')||(ch > 'a'&& ch <= 'z'))
ch--;
else if(ch == 'A')
ch = 'Z';
else if(ch == 'a')
ch = 'z';
return ch;
}