My program stop working after a bit and i dont know why

I dont know why my program stops work, im trying to make it a game but so far its failing

Im using Dev C++ 4.9.9.2 and i saved it has ".c" at the end

This is the code:

# include <stdio.h>

int main()
{
int op,op1,op2,op3,op4,op5,op6,op7,op8,op9,op10,op11;

printf("Hello, Welcome to your adventure. Your Story is that you wake up in a new world with nothing but your clothes on you back \n");
printf("You see a 1-pig, a 2-forest, and 3-lake\n");
scanf("%d",&op);
switch (op)

{
case 1:
printf("You walk up to the pig, he stares at you. OINK (^@^)~ \n");
printf("\nwill you 1-kill it, 2-turn back and walk to the forest, 3-turn back and walk to the lake?\n");
scanf("%d",&op1);
switch (op1)
{
case 1:
printf("You got three raw porkchops\n");
printf("\nYou turn back the way you came. 1-Will you go to the forest or 2-Will you go to the lake\n");
scanf("%d",&op2);
switch (op2)
{
case 1:goto l1;
case 2:goto l2;
}
case 2:goto l1;
case 3:goto l2;
}
break;
l1:
case 2:
printf("you go up the forest. what do you do? 1-You cut some wood down, 2- you go to the lake\n");
scanf("%d",&op1);
switch (op1)
{
case 1:
printf("You got some wood. 1-Make some makeshift tools? or 2-make some form of a shelter?\n");
scanf("%d",&op3);
switch (op3)
case 1:goto l3;
case 2:goto l4;

}

break;
l2:
case 3:
printf("You walk up to the lake. you see yourself, you are all dirty and ragged. would you like to clean up?1-yes , 2-no\n");
scanf("%d",&op4);
switch (op4)
{
case 1:
printf("you cleaned yourself up. what do you want to do? Explore around or if you havent headed to the forest then go there now. 1-Explore or 2-Head to the forest?\n");
scanf("%d",&op4);
switch (op4)
{
case 1:goto l5;
case 2:goto l1;
}
}
break;
l3:
case 4:
printf("you make a pickaxe, a axe, a shovel and a sword. you got spare wood, you want to make a shelter or save it? 1-shelter or 2-save it\n");
scanf("%d",op6);
switch (op6)
{
case 1: goto l10;
case 2: goto l5;
}
break;
l4:
case 6:
printf("You made a Shelter for th\e night and you have enough left for some make-shift tools or you want save it? 1-Make tools or 2-save it\n");
scanf("%d",&op5);
switch (op5)
{
case 1: goto l11;
case 2: goto l5;
}

break;
l5:
case 7:
printf("You saved the wood for future use");
printf("Do you want to explore the forest some or go into your shelter and rest for the night. 1-Explore, 2-Rest");
scanf("%d",op7);
switch (op7)
{
case 1: goto l6;
case 2: goto l7;
}
break;
l6:
case 8:
printf("You explore the forest with your make shift sword at hand and you spot something moving behind you. You turn to face it and you see it is a some form evil creature but you can't tell what it is, He tries to attack you and fails as you avoid his swing, what will you do? 1- Try to chop off something on the creature\n or\n 2-Try to get back to your house?\n");
scanf("%d", op8);
switch (op8)
{
case 1: goto l8;
case 2: goto l9;
}
break;
l7:
case 9:
printf("You rest for night but hear weird and strange noises");
sleep(3000);
goto l12;
break;
l8:
case 10:
printf("As you swing your sword at the creature but done no damage to it, It laughs and pounces on you but you avoid him and run home");
goto l9;
break;
l9:
case 11:
printf("You run back to your house");
goto l12;
break;
l10:
case 12:
printf("You make a shelter but run out of wood\n");
printf("You want to 1-Explore or 2-Rest for the night\n");
scanf("%d", op9);
switch (op9)
{
case 1: goto l6;
case 2: goto l7;
}
break;
l11:
case 13:
printf("You make some make shift tools but ran out of wood\n");
printf("You want to 1-Explore or 2-Rest for the night\n");
scanf("%d", op10);
switch (op10)
{
case 1: goto l6;
case 2: goto l7;
}
break;
l12:
case 14:
printf("You wake up after scary night but you still was able to rest a bit\n");
printf("Do you want to 1-go in to the edge of the forest and get some more wood? or 2-explore the land around you\n");
scanf("%d", op11);
switch (op11)
{
// case 1: goto l13;
// case 2: goto l14;
}
}
system("PAUSE");
}



Last edited on
Why do you have so many switch statements? I am quite sure one switch will be enough to achieve what you are trying to get. Oh and the goto statements are not recommended because they sometimes ignore the scanf function especially after a previous scanf or any function that reads from stdin. This could result in an infinite loop.


Can you post the errors you get? And please use code tags, they are the ones that look like this ("<>")
I get no errors and the goto isnt ignoring the scanf since i can input the number i want just after a few inputs later, i add a number and it just stops working

edit: i debugged the program and when it crashes it says "An Access Violation (Segmentation Fault) raised in your program
Last edited on
Topic archived. No new replies allowed.