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);
}