Thread: help with this code- loops

  1. #16
    Registered User Erikknight's Avatar
    Join Date
    Nov 2012
    Earth, Sol System.
    #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("\nYou got %d0%% correct!\nPress any key to exit.", correct);      

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

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, 02: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