i now can make it go from room0 to an adjacent room. i do have a problem with it but its not any error it actually works. now to make it continue and end were i want it. i have tried a while loop that dident work then i tryed a do while loop did the exact same thing, and i have tride them in diffrent ways with the loops but nothing seems to work how i want it. how do i make it continue and end.
yes i now these are this is what happens when i skip the design step.
thanks zacs7 that realy helped and its not realy the teachers fault its the system, i have never seen code in my life till this class, the teacher teaches the class like we have been writing code most of our life, which is mostly correct i am the exception.
and Adak thanks for the example, i kinda understand it.
Code:
#include <stdio.h>
#include <stdlib.h>
void script (int room_num){
if (room_num==0){
printf("room0\n");
}
if (room_num==1){
printf("room1\n");
}
if (room_num==2){
printf("room2\n");
}
if (room_num==3){
printf("room3\n");
}
if(room_num==-1){
printf("the walls are acid\n");
return 0;
}
}
int next_room(unsigned int a, unsigned int b)
{
static const int map[4][4] = { {1, 2,-1,-1},
{2, 0,-1,-1},
{0, 1,-1, 3},
{-1,-1,2,-1}
};
return map[a][b];
}
int conversion (char letter){
switch(letter) {
case 'n':
return 0;
case 's':
return 1;
case 'e':
return 2;
case 'w':
return 3;
default:
printf("No!, After wandering for hours you figure out %c is not a actual direction and end up walking into the slabbering fangs of a lurking Grue.\n", letter);
return 0; <---here is my small problem i want the whole program to completely end here.
}
}
int main (void)
{
char letter;
int a; //current room
printf("direction:");
scanf("%c",&letter);
int y=conversion(letter); //the number of the direction
int x=(next_room(a,y)); //the next room number
script (x);
return 0;
}
to up date the room number i was thinking x=a, would that work some how?