need to loop my prog. after the prompt

This is a discussion on need to loop my prog. after the prompt within the C++ Programming forums, part of the General Programming Boards category; //snippet of what my prog looks like printf("please enter the amount of questions evaluated ") cin>>"">>num1; printf("the amount student got ...

  1. #1
    d-dubb
    Guest

    Lightbulb need to loop my prog. after the prompt

    //snippet of what my prog looks like
    printf("please enter the amount of questions evaluated ")
    cin>>"">>num1;

    printf("the amount student got correct")
    cin>>""num2;

    div(num2,num2)* 100// this is basically
    //how its set up.
    //here's where the problem lies..
    char yn;
    printf("would you like to convet any other
    test scores\n");
    printf(" press 'y' and enter to continue
    press 'n' plus enter to exit program");
    //i need to loop the program if the user
    //selects 'y'. i have tried the book samples but oviously i'm understanding
    //the book wrong. desperate now!
    please help!!!!!

  2. #2
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    Follow the link in my sig. Under the Information heading, follow "An introduction to simple C++ functions". Look up 'getch' and the 'for' and 'do...while' loop examples.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  3. #3
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    do {

    // your code here

    } while ( user_response != 'y' && user_response != 'Y' );

    Just be sure that any variables are reinitialized when you go back to the top of the loop. One way to do this is:

    do {

    DoMyCode();

    // now prompt

    } while( user_response != 'y' && user_response != 'Y' );

    By making your code a separate function, you guarantee that the data is reinitialized every time.
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My loop within loop won't work
    By Ayreon in forum C Programming
    Replies: 3
    Last Post: 03-18-2009, 10:44 AM
  2. Visual Studio Express / Windows SDK?
    By cyberfish in forum C++ Programming
    Replies: 23
    Last Post: 01-22-2009, 01:13 AM
  3. Replies: 8
    Last Post: 12-01-2008, 09:09 AM
  4. syntax question
    By cyph1e in forum C Programming
    Replies: 19
    Last Post: 03-30-2006, 11:59 PM
  5. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM

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