help with loops

This is a discussion on help with loops within the C Programming forums, part of the General Programming Boards category; hey, im trying to write a code that generates a maze....i have everything right so far, but now need to ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    13

    help with loops

    hey, im trying to write a code that generates a maze....i have everything right so far, but now need to get the maze to print out. i know i need to use a loop but im having trouble figuring out what kind and what to write. my computer crashed so i had to rewrite this program and im not very good at this....my brain is fried. please help!

    Code:
    #include <stdio.h>
    //#include "maze_gen.c"
    #include <stdlib.h>
    #include <math.h>
    
    int main (void)
    {
     char myMaze [700];    //big enough to handle a 625 char array
     int user_n = 0;
     int i = 0;
    
    
    
     //while loops so that the user can keep tryin to enter a valid nubmer
     while(i == 0)
     {
       //ask the user what value of n for the maze they would liek to use
       printf("What value of n would you like to use-->");
       scanf("%d", &user_n);
    
       //make sure the user entered a valid number for n, greater than five and also odd
       if(user_n < 5)
       {
         printf("Not a valid number, please try again\n\n");
       }
       else if((user_n%2) == 0)
       {
         printf("Not a valid number, please try again\n\n");
    
       }
       else if(user_n > 25)
       {
         printf("Not a valid number, please try again\n\n");
       }
    
       if(((user_n%2) != 0) && (user_n >= 5) && (user_n <= 25))
       {
         i = 1;
         //printf("right entry");    check to make sure it worked properly
       }
    }
    
    //create the maze using the function call maze_create(), passing in the user_n and the array myMaze
     maze_create(myMaze, user_n);
    
    
    
    
    
    
     system("PAUSE");
     return 0;
    }

  2. #2
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    maze_create is not defined.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    9
    Observe this line in your code
    //#include "maze_gen.c"


    Quote Originally Posted by manutd
    maze_create is not defined.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    13
    thanks! any ideas on the loop?

  5. #5
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    It looks good to me. Take away the comments (aka //printf) and see what happens. If you have a specific error come back here.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    13
    well...it doesnt do anything other than print out the "what value of n" and if it is a valid number or not. i need to to print out the maze, i know that i need to use a loop to print the mazes however i for some reason cannot understand the logic behind it. not sure if i am making any sense....

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    13
    i can not figure out how to print the maze. can someone please help?? i know that this is the easiest part of the program, but i for some reason am stuck. any suggestions??? thanks

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    What have you tried? How is your maze organized? You haven't provided enough information for us to help you as your maze creation algorithm is tucked away in some black box that you haven't shown us. We don't understand your problem well enough to offer suggestions.
    My best code is written with the delete key.

  9. #9
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Show us your create_maze function and we can show you what's wrong. Without that we really can't help you.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Loops Trouble
    By rlframpton in forum C Programming
    Replies: 2
    Last Post: 04-17-2009, 01:08 AM
  2. Too many loops D:
    By F5 Tornado in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2007, 12:18 AM
  3. help with arrays and loops
    By jdiazj1 in forum C Programming
    Replies: 4
    Last Post: 11-24-2001, 03:28 PM
  4. for loops in C
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 10-15-2001, 05:09 PM
  5. exiting loops with ease?
    By KingRuss in forum Game Programming
    Replies: 3
    Last Post: 09-24-2001, 08:46 PM

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