Like Tree1Likes

help with this code- loops

This is a discussion on help with this code- loops within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <stdlib.h> #include <time.h> #include <conio.h> void print_rand_msg(const int msg_type); int main(void) { int n1; int n2; ...

  1. #16
    Registered User Erikknight's Avatar
    Join Date
    Nov 2012
    Location
    Earth, Sol System.
    Posts
    2
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <conio.h>
     
     
     
     
    void print_rand_msg(const int msg_type);
     
     
    int main(void) 
    {
    int n1;
    int n2;
    int prd, guess;
    int loop;
    int correct=0;
     
     
     
    for(loop=0; loop<10; loop++)
    { 
    srand((unsigned int)time(NULL));
     
     
    n1 = rand()%12+1;
    n2 = rand()%12+1;
    prd = n1 * n2;
     
     
    printf("\nWhat is %d x %d\?\n",n1,n2);
                            
     
     
    if(scanf("%d", &guess) != 1) 
    printf("Incorrect input.");
     
     
    else if(guess == prd) 
         {
         printf("\nCORRECT\n");
         correct++;
         }
    else
         {
         printf("\nINCORRECT\n");
         }
    }
    printf("\nYou got %d0%% correct!\nPress any key to exit.", correct);      
    getch();
    }

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,794
    Quote Originally Posted by Gareth Morgan
    how do I get the last bit of my code to repeat the application once its finished assuming the user clicks Y?
    Wrap the relevant code in a loop that repeats if the user entered Y.

    Oh, and you need to indent your code properly. At the moment, it is difficult to trace the flow of control through your code because there is no visual guide provided by proper indentation.

    Erikknight: you need to indent your code too. Furthermore, if you want to post code, then you should post it with an explanation of what it is about with respect to the topic.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 06-01-2011, 04:19 PM
  2. can i ask what is wrong with this code? [LOOPS only]
    By Huskar in forum C Programming
    Replies: 6
    Last Post: 03-18-2009, 02:05 PM
  3. Help with a code using File I/O and Loops
    By bns1201 in forum C Programming
    Replies: 27
    Last Post: 10-17-2008, 09:19 PM
  4. while loops...a problem with my simple code?
    By niceguy in forum C Programming
    Replies: 13
    Last Post: 02-20-2008, 01:59 PM
  5. Loops OR Functions!! HELP WITH THIS CODE!!!!!!!!!!
    By WIshIwasGooD in forum C++ Programming
    Replies: 4
    Last Post: 10-24-2001, 12:49 PM

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