mirror of
https://github.com/Soccera1/agg.git
synced 2025-09-20 21:57:04 +02:00
add input validation
This commit is contained in:
parent
8ed0bef631
commit
2fd00a39a1
1 changed files with 9 additions and 1 deletions
10
src/agg.c
10
src/agg.c
|
@ -47,8 +47,16 @@ int main(void) {
|
|||
printf ("Welcome to Agg! This game tests your math skills against the clock.\n\nHow to Play:\n\n1. Set Your Playtime: First, you'll decide how long you want to play by entering a duration in seconds.\n2. Solve Math Problems: Once the game starts, you'll be presented with a series of random math problems: addition, division, subtraction, and multiplication. Your goal is to solve as many as you can before time runs out.\n3. Enter Your Answer: After each problem, type your answer and press Enter. The game will immediately tell you if you're correct or incorrect.\n4. Rack Up Points: For every correct answer, you'll earn a point. Your score will be tallied at the end.\n5. Time's Up! The game ends automatically when your chosen playtime runs out. Good luck, and have fun!\n"); }
|
||||
|
||||
int accuracytype;
|
||||
char input[2];
|
||||
printf ("Would you like your accuracy as a float or as an int? Type 0 for float or 1 for int.\n");
|
||||
scanf ("%d", &accuracytype);
|
||||
scanf ("%s", &input);
|
||||
|
||||
if (isvalidnumber(input)) {
|
||||
sscanf(input, "%d", &accuracytype);
|
||||
} else {
|
||||
printf ("Error! An invalid character was entered.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int playtime;
|
||||
printf ("\nHow long would you like to play for? Answer in seconds.\n");
|
||||
|
|
Loading…
Add table
Reference in a new issue