From 622b54fe9d306e32e33ba3974111da8fa9cf76ac Mon Sep 17 00:00:00 2001 From: fdlt3859 Date: Fri, 3 Feb 2023 20:49:50 +0000 Subject: [PATCH] Added loading progress bar --- src/main/quizproject.c | 33 ++++++++++++++++++++++++++++++++- src/main/quizproject.h | 2 ++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/main/quizproject.c b/src/main/quizproject.c index 5a74f7a..e67ddfa 100644 --- a/src/main/quizproject.c +++ b/src/main/quizproject.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "quizproject.h" char answers[NUM_QUESTIONS] = {'B', 'A', 'A','B','A'}; @@ -1814,7 +1815,35 @@ void displayCredits(void) { printf("- Frau Monika Schak (Lecturer: Programming-1 in C)\n"); } -int main() { +void progress_bar(int percentage) +{ + printf("\r["); + for (int i = 0; i < 50; i++) + { + if (i < (percentage / 2)) + { + printf(">"); + } + else + { + printf(" "); + } + } + printf("] %d%%", percentage); + fflush(stdout); +} + +void v_progress_bar(int argc, char *argv[]){ + for (int i = 0; i <= 100; i++) + { + progress_bar(i); + usleep(100000); + } + printf("\n"); + +} + +int main(int argc, char *argv[]) { int choice; printf("Welcome to the Game Menu!\n"); printf("\t\t----------------------------\n\n"); @@ -1855,6 +1884,7 @@ int main() { printf("8. Exit\n"); printf("Enter your choice: "); scanf("%d", &choice); + v_progress_bar(argc,argv); switch(choice) { case 1: @@ -1897,6 +1927,7 @@ int main() { char jump_key; scanf(" %c", &jump_key); jump_key = toupper(jump_key); + v_progress_bar(argc,argv); } } feedbackForm(); diff --git a/src/main/quizproject.h b/src/main/quizproject.h index 67a4e9b..ab3055d 100644 --- a/src/main/quizproject.h +++ b/src/main/quizproject.h @@ -28,6 +28,8 @@ void displayCredits(void); void v_factorlie(void); void v_guessingGame(void); void v_guessTheWord(char word[], char guessed[]); +void progress_bar(int percentage); +void v_progress_bar(int argc, char *argv[]); void million_instructions(); void million_exit(int million_a);