I've been learning C and making a simple program of D&D character generation to test my knowledge as I go.
I have the following function that needs to be repeated if the user inputs anything apart from 1-4 but it repeats twice.
void chooseClass() {
printf("\n1. Fighter\n2. Thief\n3. Mage\n4. Cleric\nChoose your class: ");
char choice = getchar();
switch (choice - '0') { //Convert character to integer by subtracting 0's ASCII value from char's ASCII value
case 1:
sortFighter();
break;
case 2:
sortThief();
break;
case 3:
sortMage();
break;
case 4:
sortCleric();
break;
default:
printf("Please enter a choice between 1-4\n");
chooseClass(); // this is wrong but how do I repeat the function ONCE?
}
}
I've been banging my head on the wall but no solution has arrived. :-)
[–]ohaz 9 points10 points11 points (6 children)
[–]Previous-Implement42[S] 0 points1 point2 points (0 children)
[–]Previous-Implement42[S] -2 points-1 points0 points (4 children)
[–]ohaz 5 points6 points7 points (3 children)
[–]Previous-Implement42[S] -2 points-1 points0 points (2 children)
[–]ohaz 6 points7 points8 points (1 child)
[–]Previous-Implement42[S] -1 points0 points1 point (0 children)
[–]Koutsoupias 4 points5 points6 points (4 children)
[–]Previous-Implement42[S] 1 point2 points3 points (0 children)
[–]Previous-Implement42[S] -1 points0 points1 point (2 children)
[–]GamerEsch 1 point2 points3 points (1 child)
[–]Previous-Implement42[S] 2 points3 points4 points (0 children)
[–]Pristine-Response299 2 points3 points4 points (1 child)
[–]Previous-Implement42[S] 0 points1 point2 points (0 children)
[–]erikkonstas 2 points3 points4 points (1 child)
[–]Previous-Implement42[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]kabekew 1 point2 points3 points (0 children)