![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| Tags: |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |||
| [SOLVED] C program inside? 10 points to whoever can help me fix this.bear in mind I've absolutely no idea how rand works(that's the reason I'm here) #include <stdio.h> #include <stdlib.h> #define num 4 int main() { int a,b,c; int vect[num],i; int x,y,n; printf(" Introduzca numero de jugadas "); scanf("%d",&x); printf(" Introduzca monto del cual dispone "); scanf("%d",&y); do{ y--; printf(" \nLe quedan %d jugadas\n",y); for(i=0;i<num;i++){ vect[i]=rand() % 10; a=vect[i];b=vect[i];c=vect[i]; } if(a==b&&a==c){ x=2*x; printf(" Ganaste el triple\n "); } else if(a==b&&a!=c){ x=(3/2)*x; printf(" Ganaste el doble\n "); } else if(a=!b&&a==c){ x=(3/2)*x; printf(" Ganaste el doble\n "); } else if(b==c&&b!=a){ x=(3/2)*x; printf(" Ganaste el doble\n "); } else if(b!=c&&b!=a){ x=(x/2); printf(" Perdiste\n "); } while(y>0&&x>1); system("pause"); } its supposed to be a slot machine..general tips would be helpful |
| |
| |||
| I made some changes, and tried to add comments to explain what I did. Hopefully this helps some. #include <stdio.h> #include <stdlib.h> //needed for the line below where we seed //the random number generator #include <time.h> #define num 4 int main() { int a,b,c; int vect[num],i; int x,y,n; //otherwise it will generate exactly the //same "random" numbers every time srand(time(0)); printf(" Introduzca numero de jugadas "); scanf("%d",&x); printf(" Introduzca monto del cual dispone "); scanf("%d",&y); do{ y--; printf(" \nLe quedan %d jugadas\n",y); for(i=0;i<num;i++){ vect[i]=rand() % 10; //a, b, and c all ended up with the same value, //the last random number you generated } //moved this outside the loop //so they don't all have the same value a = vect[0]; b = vect[1]; c = vect[2]; if(a==b&&a==c){ x=2*x; printf(" Ganaste el triple\n "); } else if(a==b&&a!=c){ x=(3/2)*x; printf(" Ganaste el doble\n "); } else if(a=!b&&a==c){ x=(3/2)*x; printf(" Ganaste el doble\n "); } else if(b==c&&b!=a){ x=(3/2)*x; printf(" Ganaste el doble\n "); } else if(b!=c&&b!=a){ x=(x/2); printf(" Perdiste\n "); } }//added a } that was missing while(y>0&&x>1); system("pause"); } |
![]() |
| Thread Tools | |
| Display Modes | |
| |