Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Infinite loop

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
ManOnMoon
Cheater
Reputation: 0

Joined: 17 Mar 2009
Posts: 26

PostPosted: Tue Feb 16, 2010 9:48 pm    Post subject: Infinite loop Reply with quote

Ok so for those who read my last post on my craps game thank you so much except I am stuck on this last part where I have to set it so that when you roll anything except for a losing number it becomes your point. You then keep rolling until you roll your point where you win or roll a 7 and you lose here is my piece of code.

Code:
else if ( (sum!=7)||(sum!=3)||(sum!=12)||(sum!=11)||(sum!=1)){
          sum = point;
           printf ("Your point is %d.", point);
           while ( point != 7){
             
              printf ("Rolling...%d", sum);
              if ( (sum == point) ){
                 printf ("You made the point\n\n");
                  printf ("You win $%d.00\n\n", bet);
                   printf ("You have $%d.00.\n", bank);

              } else if ( (sum == 7)){
                 printf ("Seven out.\n\n");
                   printf ("You lose $%d.00.\n", bet);
         
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Tue Feb 16, 2010 10:09 pm    Post subject: Reply with quote

so uhhh what's the problem again ?
Back to top
View user's profile Send private message
ManOnMoon
Cheater
Reputation: 0

Joined: 17 Mar 2009
Posts: 26

PostPosted: Tue Feb 16, 2010 10:28 pm    Post subject: Reply with quote

When I run the program it no longer rolls the dice between 1-12 it shoots up to 1000+ and it continues in a loop which is not what I want. I need it to make sure that the point and the random roll are equal to each other.
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Tue Feb 16, 2010 10:38 pm    Post subject: Reply with quote

can you post the full source ?
Back to top
View user's profile Send private message
ManOnMoon
Cheater
Reputation: 0

Joined: 17 Mar 2009
Posts: 26

PostPosted: Wed Feb 17, 2010 1:31 am    Post subject: Reply with quote

Alright here is the full source I fixed the infinite loop by adding breaks except my point does not match what is rolled out. I get random numbers for all and sometimes it does not go through the required statements.


Here is my source

Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>


int rollone(int sides){
int r,A,B,rprime;
r=random();
A=1;
B=sides;
rprime=(int)floor(r/(RAND_MAX+1.0)*(B-A+1.0))+1;
return rprime;
}
int roll(){
   int die1,die2,sum;
   die1 = rollone(6);
   die2 = rollone(6);
   sum = die1 + die2;
   return sum;
}

int main (void){

int bet,bank,sum,roll2;

 


bank = 100;

printf("Welcome to my casino. The game this evening\n");
printf("is Craps. (Pass line bets only, but what do\n");
printf("you want from a class project?)\n\n");
printf("The minumum bet this evening is $2.00\n\n");


  while ( bank > 2 ){
          printf( "$You have %d.00.\n", bank);
     printf( "How much would you like to bet?");
        scanf( "%d",&bet);
   
       srandom(time(NULL));

   
     
     if (bet > bank){
        printf ("Sorry you do not have that much money\n");
        break;
     }
      else if ( bet >= 2 && bet <= bank){
       
      bank = bank - bet;
               
        printf ("Coming out...%d\n",roll());
                sum = roll();
        if ( (sum == 7) || (sum == 11)) {
          bank = bank +bet +bet;
           printf ("A pass. We have a winner\n\n");
           printf ("You win $%d.00\n\n", bet);
           printf ("You have $%d.00.\n", bank);
         
        }
else if((sum==1)||(sum==3)||(sum==12)){
          
           printf ("Craps.\n\n");
           printf ("You lose $%d.00.\n\n", bet);
         
        }
 else  if (sum!=7 || sum!=11 || sum!=1 || sum!=3 || sum !=12){
             printf ("your point is %d\n", sum);
      while ( roll2!=sum || roll2!=7){

      printf("Rolling...%d\n",roll());
                  roll2 = roll();
                 if (roll2 == sum){
              bank = bank +bet +bet;
           printf ("You rolled your point\n\n");
           printf ("You win $%d.00\n\n", bet);
           printf ("You have $%d.00.\n", bank);
         break;
                }
         else if (roll2 == 7){
                         printf("Rolling...%d\n",roll2);
           printf (" Seven out\n\n");
                          printf ("You lose $%d.00.\n\n", bet);
         break;
                    }

}
                   
                   
}





         
      
      
}   else if (( bet < 2) && (bet >=1)){
         bank = bank + bet;
         printf ("Sorry the minimum bet is $2.00\n");
      }
  else if ( ((bet == 0)||(bank < 2)) ){
        printf (" Your final bankroll is $%d.00\n", bank);
        if ( bank > 0){
           printf ("Looks like you had a good night.\n");
           printf ("See the cashier on your way out.\n");
            return 0;
        } else if ((bank = 0)){
           printf ("Better luck next time.\n");
         return 0;
        }
      
       
   }   
  }
   


return 0;
}

   
Back to top
View user's profile Send private message
sloppy
Expert Cheater
Reputation: 0

Joined: 17 Aug 2008
Posts: 123

PostPosted: Wed Feb 17, 2010 2:24 am    Post subject: Reply with quote

I'm pretty clueless when it comes to craps and your code is an unsightly mess, but at a glance..

Code:
while ( roll2!=sum || roll2!=7){

      printf("Rolling...%d\n",roll());     // <- You are outputting this value
                  roll2 = roll();          //    and then.. rolling a new one?


Is that not the cause of your point mismatch?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites