Hi so I'm still learning C and here's what I came up with. My problem is that it wont start to the beginning if the user inputted the variable 'number' to less than or equal to 0. Any tips? Also mind if I ask, how to loop to the beginning when you use a function?
void main() {
int x = 0, y = 0, m, n, number, life = 4;
char choice;
int a[R][C] = { {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0} };
do {
printf("\t\t\t Welcome to my game");
Sleep(2000);
printf("\n\n This game is all about guessing where your number is located in the matrix");
Sleep(2000);
printf("\n\n\t\t\t\tOnly 1 player\n");
Sleep(2000);
printf("\n\n You are betting your own very life! \t\t\tYou have 5 tries");
Sleep(1000);
printf("\n\nEnter your number: ");
scanf("%d", &number);
system("cls");
if (number <= 0) {
system("cls");
printf("Only positive numbers allowed");
printf("\nRetry? Y/N: ");
fflush(stdin);
scanf("%c", &choice);
fflush(stdin);
if (choice == 'n' || choice == 'N') {
system("cls");
printf("Thanks for playing");
break;
}
system("cls");
break;
}
display(a);
printf("\n\nInputted number is %d", number);
printf("\n\nYour number is now being placed at a random location");
printf("\n\nGuess where your number is located (row) (column)");
printf("\n\nNote: Enter only numbers 1-4 or else you'll be wrong");
printf("\n\nEnter coordinates: ");
scanf("%d%d", &m, &n);
printf("\n");
placingguess(a, number, m, n, life);
break;
} while (choice != 'n' || choice != 'N');
getch();
}
Aucun commentaire:
Enregistrer un commentaire