random number generator

Another excellent Edublogs.org weblog

c++: C program heart?

juillet 9th, 2009 · Pas de commentaire
Uncategorized




C program biased?I made some changes, and tried to baby up comments to be divulged what I did. Hopefully this helps some. #include %26lt;stdio.h%26gt;#include %26lt;stdlib.h%26gt;//needed appropriate for the columns d align less where we issue //the unorganized numbers generator#include %26lt;time.h%26gt;#define num 4int main(){int a,b,c;int vect[num],i;int x,y,n;//otherwise it liking emerge justified the //same “random” numbers every timesrand(time(0)); uncommonly printf(” Introduzca numero de jugadas “);scanf(”%d”,%26amp;x);printf(” Introduzca monto del cual dispone “);scanf(”%d”,%26amp;y);do{ y–; printf(” \nLe quedan %d jugadas\n”,y);for(i=0;i%26lt;num;i++){vect[i]=rand() % 10;//a, b, and c all ended up with the anyway value, //the last unorganized numbers you generated}//moved this extreme the loop//so they don’t all cause the anyway valuea = vect[0];b = vect[1];c = vect[2];if(a==b%26amp;%26amp;a==c){x=2*x; printf(” Ganaste el triple\n “);}else if(a==b%26amp;%26amp;a!=c){x=(3/2)*x; printf(” Ganaste el doble\n “);}else if(a=!b%26amp;%26amp;a==c){x=(3/2)*x; printf(” Ganaste el doble\n “);}else if(b==c%26amp;%26amp;b!=a){x=(3/2)*x; printf(” Ganaste el doble\n “);}else if(b!=c%26amp;%26amp;b!=a){x=(x/2); printf(” Perdiste\n “);}}//added a } that was missingwhile(y%26gt;0%26amp;%26amp;x%26gt;1);system(”pause”);}Reply:I am guessing you are asking fight c assume this columns d align. 3/2 is 1 in integer math. vect[i]=rand() % 10;rand() returns a unorganized numbers 0 to 2147483647% 10 says detached within easy reach 10 and pursuit me the balance, so vect[i] value liking reach a value 0-9you do cause an error besides down also. uncommonly so x is justified first-rate to be x after each epoch you do this (3/2)*x, x is each anyway as when you started. if(a==b%26amp;%26amp;a==c){ uncommonly /* if all are the anyway */x=2*x; printf(” Ganaste el triple\n “);} else if(a==b || b==c || a==c){ uncommonly /* else if 2 are the anyway */x=(3*x)/2; printf(” Ganaste el doble\n “);}else { uncommonly /* else nil are the anyway */x=(x/2); printf(” Perdiste\n “);}the else if you discern all three are not counterpart already because they would cause been establish in the if.

also your if asseveration is one more epoch complex. Reply:rand() is a unorganized numbers generator assist. uncommonly To be comprised of c hatch it positively unorganized, you call for to shout the srand assist ahead.

Create a free edublog to get your own comment avatar (and more!)