Like Tree1Likes
  • 1 Post By Matticus

X.exe has stopped working, Windows is checking for a solution to the problem

This is a discussion on X.exe has stopped working, Windows is checking for a solution to the problem within the C Programming forums, part of the General Programming Boards category; My code compiles fine but whenever I run it I get a popup window that states DW.exe has stopped working, ...

  1. #1
    Registered User
    Join Date
    May 2012
    Location
    Milwaukee
    Posts
    28

    X.exe has stopped working, Windows is checking for a solution to the problem

    My code compiles fine but whenever I run it I get a popup window that states DW.exe has stopped working, Windows is checking for a solution. What could be causing this? I cannot trouble shoot this one because it compiles....

    DW.c

    Code:
    #include <stdio.h>
    #include <stdlib.h> /* required for randomize() and random() */
    #include <conio.h>  /* required for clrscr() */
    #include <time.h> 
    
    
    
    
    void Drug_buy(char city, 
                       double *my_money_ptr, 
                       int *my_coke_units_ptr, 
                       int *my_heroin_units_ptr, 
                       int *my_crack_units_ptr, 
                       int *my_pcp_units_ptr, 
                       int *my_acid_units_ptr, 
                       int *my_pot_units_ptr )
    {
              srand(time(NULL));
              double coke_price = 30000 *rand();
              double heroin_price = 5000 * rand();
              double crack_price = 1000 *rand();
              double pcp_price= 800 *rand();
              double acid_price = 500 *rand();
              double pot_price =100 *rand();
    
    
          start_buy :  
              
          printf(" %s City Drug Prices\n", city);
          printf("--------------------------------\n");
          printf(" What do you want to buy?\n");
          printf("1: Coke at %d dollars per unit\n", coke_price);   
          printf("2: Heroin at %d dollars per unit\n", heroin_price);  
          printf("3: Crack at %d dollars per unit\n", crack_price);    
          printf("4: PCP at %d dollars per unit\n", pcp_price);  
          printf("5: Acid at %d dollars per unit\n", acid_price); 
          printf("6: pot at %d dollars per unit\n", pot_price); 
          
          
          int drug_choice_selection;
          char drug_choice[100];
          printf("How Much? \n");
                     
          fgets(drug_choice, sizeof(drug_choice), stdin);
          sscanf(drug_choice, "%d", &drug_choice_selection);  
          
     
       
               switch(drug_choice_selection)
               {
               case( '1' ):
                     {
               
                     int coke_choice;
                     char coke_Col_line[100];
                     printf("How Much? \n");
                     
                     fgets(coke_Col_line, sizeof(coke_Col_line), stdin);
                     sscanf(coke_Col_line, "%d", &coke_choice);
                     
                     if(coke_choice*coke_price > *my_money_ptr)
                     {
                     printf("You don't have enough Money!\n");
                     printf("Please try again.....\n");
                     goto start_buy;
                     }
                     else
                     {
                     *my_money_ptr = (*my_money_ptr - (coke_choice*coke_price));
                     *my_coke_units_ptr = coke_choice;
                     }
                     }
                     
       
       
               case( '2' ):
                     {
                     int heroin_choice;
                     char heroin_Col_line[100];
                     printf("How Much? \n");
                     
                     fgets(heroin_Col_line, sizeof(heroin_Col_line), stdin);
                     sscanf(heroin_Col_line, "%d", &heroin_choice);
                     
                     if(heroin_choice*heroin_price > *my_money_ptr)
                     {
                     printf("You don't have enough Money!\n");
                     printf("Please try again.....\n");
                     goto start_buy;
                     }
                     else
                     {
                     *my_money_ptr = (*my_money_ptr - (heroin_choice * heroin_price));
                     *my_heroin_units_ptr = heroin_choice;
                     }
                     }
                case( '3' ):
                     goto start_buy;
       
       
               case( '4' ):
                     goto start_buy;
    
    
    
    
    
    
    
    
               case( '5' ): 
                     goto start_buy;
    
    
    
    
    
    
    
    
               case( '6' ): 
                     goto start_buy;   
    
    
    
    
               case( '7'): 
                     goto start_buy;    
       
               default :
                       goto start_buy;
       
      /* try again */
       }   
              
         }
         
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    int main()
    {
          double my_money;
    	  int my_coke_units;
    	  int my_heroin_units;
    	  int my_crack_units;
    	  int my_pcp_units;
    	  int my_acid_units;
    	  int my_pot_units;
        
          int days_left = 31;    
    while(days_left > 0)
    {
          printf(" Day %d of your quest. Where do you want to go\n", days_left);
          
          printf("----------------------------------------------\n");
          
          printf("1: Chicago\n");   
          printf("2: Detroit\n");  
          printf("3: Disneyland\n");    
          printf("4: Mexico City\n");  
          printf("5: Vatican City\n"); 
          printf("6: Columbo\n");
          
          int city_choice_selection;
          char city_choice[100];
    
    
    
    
                     
          fgets(city_choice, sizeof(city_choice), stdin);
          sscanf(city_choice, "%d", &city_choice_selection); 
          
          
          switch( city_choice_selection)
          {
          case 1: 
                {  
           Drug_buy(city_choice_selection, 
                          &my_money, 
                          &my_coke_units, 
                          &my_heroin_units, 
                          &my_crack_units, 
                          &my_pcp_units, 
                          &my_acid_units, 
                          &my_pot_units );         
                          }
           
           case 2: 
                 
                 
           case 3: 
                 
           case 4: 
    
    
    
    
           default:
                   printf("this is the default\n");
           }
    days_left = days_left - 1;
    
    
    
    
    
    
    
    
    }    
    
    
    
    
    
    
    
    
     
       system("pause");                     /* the fix for the collapsing window*/
        return (0);
    }

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    2,692
    You could troubleshoot it with a debugger...

    What do you enter at the first prompt?

  3. #3
    Registered User
    Join Date
    May 2012
    Location
    Milwaukee
    Posts
    28
    I entered 1 and Bang...... Show's over

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    2,692
    Yes, but you're not looking for a number. You're looking for a city name:

    Code:
    printf("1: Chicago\n");   
    printf("2: Detroit\n");  
    printf("3: Disneyland\n");    
    printf("4: Mexico City\n");  
    printf("5: Vatican City\n"); 
    printf("6: Columbo\n");
           
    int city_choice_selection;
    char city_choice[100];
    
    fgets(city_choice, sizeof(city_choice), stdin);     // <--------
    sscanf(city_choice, "%d", &city_choice_selection);
    I'm guessing this means you didn't write this yourself? Try entering a city name. It still won't work, but it shouldn't crash again right away.

    Also, check the warnings when you compile:

    Code:
    main.c||In function 'Drug_buy':|
    main.c|29|warning: format '%s' expects type 'char *', but argument 2 has type 'int'|
    main.c|32|warning: format '%d' expects type 'int', but argument 2 has type 'double'|
    main.c|33|warning: format '%d' expects type 'int', but argument 2 has type 'double'|
    main.c|34|warning: format '%d' expects type 'int', but argument 2 has type 'double'|
    main.c|35|warning: format '%d' expects type 'int', but argument 2 has type 'double'|
    main.c|36|warning: format '%d' expects type 'int', but argument 2 has type 'double'|
    main.c|37|warning: format '%d' expects type 'int', but argument 2 has type 'double'|
    Salem likes this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ****.exe has stopped working
    By kawaikx15 in forum C Programming
    Replies: 10
    Last Post: 11-19-2011, 07:38 AM
  2. .exe has stopped working
    By bluesky16 in forum C++ Programming
    Replies: 8
    Last Post: 02-21-2011, 12:58 PM
  3. vshost.exe has stopped working
    By Marty21 in forum C# Programming
    Replies: 1
    Last Post: 06-08-2009, 11:41 AM
  4. Replies: 4
    Last Post: 03-26-2008, 09:48 AM
  5. Mouse scroll stopped working
    By Waldo2k2 in forum Tech Board
    Replies: 2
    Last Post: 10-12-2004, 12:25 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21