Thread: C Program Not Properly Calculating

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    10

    C Program Not Properly Calculating

    I'm writing a slot machine program where you are supposed to start with 1000 quarters but for some reason its counting down from some random number higher than the quarters=1000; I declared. The program is supposed to run till you run out of quarters. Can someone shed light on my problem?
    The first machine pays 25 quarters every 33th time it is played;
    the second machine pays 75 quarters every 99th time it is played;
    the third pays 7 quarters every 9th time it is played.

    Code:
    #include <stdio.h>
    int slot1(int, int  );
    int slot2(int, int  );
    double convertQuarters (int);
    void main(){
        int timesPlayed = 0;
    	int timesPlayed2 = 0;
    	int input3;
    	double x;
    	
    	int quarters=1000;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    	while(quarters>0) {
    //quarters--;
    	quarters+= slot1(timesPlayed++, --quarters );
    	quarters+= slot2(timesPlayed2++, --quarters );	
    	quarters+= slot3(timesPlayed2++, --quarters );
    //timesPlayed++;
    	/*	printf ("\nSlot Machine Two\n");
    
    
    
    
    
    
    
    
    
    
    		printf("Press 1 to Insert Quarter\n");
    		scanf ("%d", &input2);
    		printf("Sorry You Lose\n");
    
    
    
    
    
    
    	//	winnings = .25*75;
    		//quarters=quarterTotal-99;
    	//	total=.25*quarterTotal;
    
    
    		if (input1==99){
    			printf ("You've Won 75 Quarters on machine 1!\nYou've won $%.2lf\n", winnings);
    		printf ("You Have %.2lf quarters left which equals $%.2lf\n\n", quarters, total);
    		}
    
    
    		printf ("\nSlot Machine Three");
    
    
    
    
    
    
    
    
    
    
    
    
    		printf("\nPress 1 to Insert Quarter\n");
    		scanf ("%d", &input3);
    		printf("Sorry You Lose\n");
    
    
    
    
    
    
    	
    		quarters=quarterTotal-9;
    		total=.25*quarterTotal;
    		if (input1==9){
    			printf ("You've Won 7 Quarters on machine 1!\nYou've won $%.2lf\n", winnings);
    			printf ("You Have %.2lf quarters left which equals $%.2lf", quarters, total);
    			system ("pause");
    		}
    		*/
           
            printf ("You have %d quarters left\n", quarters);
            
            } //End While Loop
    
    
    system ("pause");
    }
    int slot1(int timesPlayed, int quarters)
    {
        int winnings=0;
    	printf ("Slot Machine One\n");  
    
    
    
    
    
    
    
    
    
    
    
    
    	
    	
    	
    	
    	if (timesPlayed%33==0){
    	printf("You won on slot machine 1\n");
    
    
    	quarters+=25;
    	printf ("You have %d quarters left\n", quarters);
    	
        winnings= 25;
    	}
    	
    	return winnings;
    	
    }
    int slot2(int timesPlayed, int quarters)
    {
        int winnings=0;
    	printf ("Slot Machine Two\n");  
    
    
    
    
    
    
    
    
    
    
    	
    	
    	
    	
    	if (timesPlayed%99==0){
    	printf("You won on slot machine 2\n");
    
    
    	quarters+=75;
    	printf ("You have %d quarters left\n\n", quarters);
    	printf ("You have %.2lf quarters left\n", convertQuarters(quarters));
        winnings= 75;
    	}
    	
    	return winnings;
    	
    }
    int slot3(int timesPlayed, int quarters)
    {
        int winnings=0;
    	printf ("Slot Machine Three\n");  
    
    
    	if (timesPlayed%9==0){
    	printf("You won on slot machine 3\n");
    
    
    	quarters+=25;
    	printf ("You have %d quarters left\n\n", quarters);
    	printf ("You have %.2lf quarters left\n", convertQuarters(quarters));
        winnings= 25;
    	}
    	
    	return winnings;
    	
    }
      double convertQuarters (int quarters)
      {
             double result;
             result=quarters*.25;
             
             
             return result;
             
             
             
             }
    Last edited by andynov123; 09-18-2011 at 12:23 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to program properly
    By Richardcavell in forum C Programming
    Replies: 13
    Last Post: 02-23-2011, 03:55 PM
  2. why is math not calculating properly
    By kburyanek in forum C Programming
    Replies: 9
    Last Post: 10-15-2009, 07:46 AM
  3. Can't Get This Program To Work Properly
    By jbyers19 in forum C Programming
    Replies: 5
    Last Post: 03-09-2006, 10:59 PM
  4. Replies: 2
    Last Post: 11-10-2003, 09:12 PM
  5. plz hlp me. program not running properly
    By jfl in forum C Programming
    Replies: 5
    Last Post: 02-11-2002, 03:58 PM