Thread: Loop

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    19

    Loop

    2 users enter 2 different numbers, and I want to continue to ask to User 1 and User 2 to try to guess the opponent numbers. When one of the Users guess the other User numbers, the loop ends and the "Game is Over"

    I cannot use pointers.

    I don't really know how to do it, i'm still kinda new in c programming.

    I was trying to put 2 Do While loops inside another Do While, but it's not working.

    Any help?

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    161
    What code have you got so far?

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    19
    Well this is a little more complicated that I said in the first post.

    This is a "game" where booth players choose their initial positions and booth players have a "cannon" to shoot the opponent.

    To shoot, the players have to choose the angle and the velocity, and the movement are made acording the Equations of Motion

    The initial X and initial Y are choosen in the beggining of the game(...)
    Code:
    do {
     do {
      printf("\n|+++++++++|\n");
      printf("|Player 1|\n");
      printf("|+++++++++|\n");
      
      printf("\n->Angle:");
      scanf("%f", &angle_1);
      printf("\n->Velocity:");
      scanf("%f", &v_initial_1);
       
      angle_radians1=(angle_1*M_PI)/180;
      
     
      for(t=0.1;t<=3.0;t=t+0.1) {
      x_1=x_initial_1+(v_initial_1*cos(angle_radians1)*t);
      y_1=y_initial_1+(v_initial_1*sin(angle_radians1)*t)+0.5*(g*(t*t));
      
      if (x_1<0 || x_1>1000 || y_1<0 || y_1>1000) {
                printf("OUT OF LIMITS");
                }
      
      printf("\nTo t=%.2f the position is X=%.0f and Y=%.0f\n", t,x_1,y_1);
      
      
      }} while (and don't know what to put here);
      
      do {
      printf("\n|+++++++++|\n");
      printf("|Player 2|\n");
      printf("|+++++++++|\n");
      
      printf("\n->Angle:");
      scanf("%f", &angle_2);
      printf("\n->Velocity:");
      scanf("%f", &v_initial_2);
       
      angle_radians2=(angle_2*M_PI)/180;
      
     
      for(t=0.1;t<=3.0;t=t+0.1) {
      x_2=x_initial_2+(v_initial_2*cos(angle_radians2)*t);
      y_2=y_initial_2+(v_initial_2*sin(angle_radians2)*t)+0.5*(g*(t*t));
      
      printf("\nTo t=%.2f the position is X=%.0f and Y=%.0f\n", t,x_2,y_2);
      
      
      }} while (and don't know what to put here);
    
    } while (and don't know what to put here)
    ..
    _________________________


    A lot of errors I know because I am still experimenting, this is just for you to understand the idea.
    Last edited by Gotze; 11-20-2011 at 06:23 AM.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    And should we wait for you to come up with a third completely different version of this question?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 23
    Last Post: 04-05-2011, 03:40 PM
  2. for loop ignoring scanf inside loop
    By xIcyx in forum C Programming
    Replies: 2
    Last Post: 04-17-2007, 01:46 AM
  3. loop the loop - feeling foolish
    By estos in forum C Programming
    Replies: 2
    Last Post: 04-07-2007, 02:45 AM
  4. Replies: 3
    Last Post: 03-14-2006, 11:09 AM
  5. While loop ..crating an infanat loop
    By fmchrist in forum C Programming
    Replies: 7
    Last Post: 01-14-2006, 10:52 AM