lundi 26 octobre 2020

How to keep asking the user for input until they choose to exit?

How do I keep asking the user to input a number until they choose to exit? When I enter in another number, it doesn't keep going.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int numSets;
int a = 1, b = 53;    
int c;

int main()
{
    int ranOne, ranTwo, ranThree, ranFour, ranFive, ranSix;

    srand(time(NULL));

    printf("Enter the amount of sets you want otherwise put -1 to exit:\n");
    scanf("%d", &numSets);

    for (c = 1; c <= numSets; c++) {
        ranOne = (rand() % (b - a + 1)) + a;
        ranTwo = (rand() % (b - a + 1)) + a;
        ranThree = (rand() % (b - a +1)) + a;
        ranFour = (rand() % (b - a + 1)) + a;
        ranFive = (rand() % (b - a + 1)) + a;
        ranSix = (rand() % (b - a + 1)) + a;

        printf("Set # %d of six numbers: %d %d %d %d %d %d\n", c, ranOne, ranTwo, ranThree, ranFour, ranFive, ranSix);
    }

    if(numSets == -1) {
        printf("You have exited the application");
    }

    return 0;
}



Aucun commentaire:

Enregistrer un commentaire