Random not working properly
Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int main()
{
int ch;
clrscr();
while(ch!='0')
{
puts ("Press the number of selection");
puts ("[1] Perfect Numbers");
puts ("[2] Fibonacci Numbers");
puts ("[3] Jack-En-Poy");
puts ("[0] EXIT\n\n");
while((ch=getch())!='0')
{
if(ch=='1')
{
int p,N[100] = {0},d,c,E=0;
printf("Input a number: ");
scanf("%d",&p);
for(d=1,c=0;d<p;d++)
{
if(p%d==0)
{
N[c]=d;
c++;
}
}
c=0;
while(N[c]!=0)
{
E=E+N[c];
c++;
}
printf("\n%d = 1",E);
c=1;
while(N[c]!=0)
{
printf(" + %d",N[c]);
c++;
}
if(p==E)
{
printf("\nPerfect!");
}
if(p!=E)
{
printf("\nDeficient!");
}
getch();
clrscr();
break;
}
if(ch=='2')
{
int c,N,N2,f,temp;
printf("Enter a Number: ");
scanf("%d",&f);
printf("0 1 ");
for(N=0,N2=1,c=1;c<=f;c=c+1)
{
if(c==(N+N2))
{
printf("%d ",c);
N=N2;
N2=c;
}
}
getch();
clrscr();
break;
}
if(ch=='3')
{
int AI;
char you;
printf("[S] scissors\n[P] Paper\n[R] Rock\nSelect your move:\n");
you=getchar();
AI=random(3);
if(AI==0)
{
printf("Computer:Scissors\n");
if(you=='S')
printf("DRAW!");
if(you=='P')
printf("LOSE!");
if(you=='R')
printf("WIN!");
}
if(AI==1)
{
printf("Computer:Paper\n");
if(you=='S')
printf("WIN!");
if(you=='P')
printf("DRAW!");
if(you=='R')
printf("LOSE!");
}
if(AI==2)
{
printf("Computer:Rock\n");
if(you=='S')
printf("LOSE!");
if(you=='P')
printf("WIN!");
if(you=='R')
printf("DRAW!");
}
AI=0;
getch();
clrscr();
break;
}
}
}
return 0;
}
I have a problem in my Jack-En-Poy. At first it works but the second time around the program will pass around you=getchar() and will instantly prints the result without asking the user for the input.